From 71522973a71f752f4f5074adbeba47654838bbdd Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 24 Mar 2025 16:50:39 +0100 Subject: [PATCH 001/153] Refactor schematic checks to handle unseen notifications --- .../src/de/steamwar/sql/CheckedSchematic.java | 34 ++++++++++++++++--- .../src/de/steamwar/messages/Chatter.java | 9 +++-- .../velocitycore/commands/CheckCommand.java | 28 ++++++++------- .../listeners/ConnectionListener.java | 12 +++++++ 4 files changed, 62 insertions(+), 21 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java b/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java index e173d4131..de68377a9 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java +++ b/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java @@ -37,15 +37,26 @@ public class CheckedSchematic { private static final SelectStatement nodeHistory = new SelectStatement<>(table, "SELECT * FROM CheckedSchematic WHERE NodeId = ? AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC"); private static final Statement insert = table.insertAll(); - public static void create(int nodeId, String name, int owner, int validator, Timestamp startTime, Timestamp endTime, String reason){ - insert.update(nodeId, owner, name, validator, startTime, endTime, reason); + private static final SelectStatement getUnseen = new SelectStatement<>(table, "SELECT * FROM CheckedSchematic WHERE Seen = 0 AND NodeOwner = ? ORDER BY StartTime DESC"); + private static final Statement updateSeen = new Statement("UPDATE CheckedSchematic SET Seen = ? WHERE StartTime = ? AND EndTime = ? AND NodeName = ?"); + + public static void create(int nodeId, String name, int owner, int validator, Timestamp startTime, Timestamp endTime, String reason, boolean seen, String nodeType) { + insert.update(nodeId, owner, name, validator, startTime, endTime, reason, seen, nodeType); } - public static void create(SchematicNode node, int validator, Timestamp startTime, Timestamp endTime, String reason){ - create(node.getId(), node.getName(), node.getOwner(), validator, startTime, endTime, reason); + public static void create(int nodeId, String name, int owner, int validator, Timestamp startTime, Timestamp endTime, String reason, String nodeType) { + create(nodeId, name, owner, validator, startTime, endTime, reason, true, nodeType); } - public static List getLastDeclinedOfNode(int node){ + public static void create(SchematicNode node, int validator, Timestamp startTime, Timestamp endTime, String reason, boolean seen) { + create(node.getId(), node.getName(), node.getOwner(), validator, startTime, endTime, reason, seen, node.getSchemtype().toDB()); + } + + public static void create(SchematicNode node, int validator, Timestamp startTime, Timestamp endTime, String reason) { + create(node.getId(), node.getName(), node.getOwner(), validator, startTime, endTime, reason, true, node.getSchemtype().toDB()); + } + + public static List getLastDeclinedOfNode(int node) { return statusOfNode.listSelect(node); } @@ -53,6 +64,10 @@ public class CheckedSchematic { return nodeHistory.listSelect(node.getId()); } + public static List getUnseen(SteamwarUser owner) { + return getUnseen.listSelect(owner); + } + @Field(nullable = true) private final Integer nodeId; @Field @@ -71,6 +86,10 @@ public class CheckedSchematic { @Getter @Field private final String declineReason; + @Getter + private boolean seen; + @Getter + private final String nodeType; public int getNode() { return nodeId; @@ -83,4 +102,9 @@ public class CheckedSchematic { public int getSchemOwner() { return nodeOwner; } + + public void setSeen(boolean seen) { + this.seen = seen; + updateSeen.update(seen, startTime, endTime, nodeName); + } } diff --git a/VelocityCore/src/de/steamwar/messages/Chatter.java b/VelocityCore/src/de/steamwar/messages/Chatter.java index 607b4fd20..f5a0b0f2f 100644 --- a/VelocityCore/src/de/steamwar/messages/Chatter.java +++ b/VelocityCore/src/de/steamwar/messages/Chatter.java @@ -85,12 +85,15 @@ public interface Chatter { else return withPlayer.apply(player); } - default void withPlayerOrOffline(Consumer withPlayer, Runnable withOffline) { + default boolean withPlayerOrOffline(Consumer withPlayer, Runnable withOffline) { Player player = getPlayer(); - if(player == null) + if(player == null) { withOffline.run(); - else + return false; + } else { withPlayer.accept(player); + return true; + } } default void withPlayer(Consumer function) { withPlayerOrOffline(function, () -> {}); diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java index c678fa4c2..f8faddbe5 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java @@ -41,6 +41,7 @@ import java.time.Instant; import java.util.List; import java.util.*; import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; import java.util.logging.Level; public class CheckCommand extends SWCommand { @@ -237,25 +238,29 @@ public class CheckCommand extends SWCommand { } private void accept(){ - if(concludeCheckSession("freigegeben", fightTypes.get(schematic.getSchemtype()))) { + concludeCheckSession("freigegeben", fightTypes.get(schematic.getSchemtype()), () -> { Chatter owner = Chatter.of(SteamwarUser.get(schematic.getOwner()).getUUID()); - owner.withPlayerOrOffline( + boolean isOnline = owner.withPlayerOrOffline( player -> owner.system("CHECK_ACCEPTED", schematic.getSchemtype().name(), schematic.getName()), () -> DiscordAlert.send(owner, Color.GREEN, new Message("DC_TITLE_SCHEMINFO"), new Message("DC_SCHEM_ACCEPT", schematic.getName()), true) ); notifyTeam(new Message("CHECK_ACCEPTED_TEAM", schematic.getName(), owner.user().getUserName())); - } + + return isOnline; + }); } private void decline(String reason){ - if(concludeCheckSession(reason, SchematicType.Normal)) { + concludeCheckSession(reason, SchematicType.Normal, () -> { Chatter owner = Chatter.of(SteamwarUser.get(schematic.getOwner()).getUUID()); - owner.withPlayerOrOffline( + boolean isOnline = owner.withPlayerOrOffline( player -> owner.system("CHECK_DECLINED", schematic.getSchemtype().name(), schematic.getName(), reason), () -> DiscordAlert.send(owner, Color.RED, new Message("DC_TITLE_SCHEMINFO"), new Message("DC_SCHEM_DECLINE", schematic.getName(), reason), false) ); notifyTeam(new Message("CHECK_DECLINED_TEAM", schematic.getName(), owner.user().getUserName(), reason)); - } + + return isOnline; + }); } private void notifyTeam(Message message) { @@ -264,14 +269,12 @@ public class CheckCommand extends SWCommand { } private void abort(){ - concludeCheckSession("Prüfvorgang abgebrochen", null); + concludeCheckSession("Prüfvorgang abgebrochen", null, () -> true); } - private boolean concludeCheckSession(String reason, SchematicType type) { - boolean exists = SchematicNode.getSchematicNode(schematic.getId()) != null; - - if(exists) { - CheckedSchematic.create(schematic, checker.user().getId(), startTime, Timestamp.from(Instant.now()), reason); + private void concludeCheckSession(String reason, SchematicType type, Supplier sendMessageIsOnline) { + if(SchematicNode.getSchematicNode(schematic.getId()) != null) { + CheckedSchematic.create(schematic, checker.user().getId(), startTime, Timestamp.from(Instant.now()), reason, sendMessageIsOnline.get()); if(type != null) schematic.setSchemtype(type); } @@ -282,7 +285,6 @@ public class CheckCommand extends SWCommand { if(subserver != null) subserver.stop(); }).schedule(); - return exists; } private void remove() { diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java index 95edeabbe..f4bc705ab 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java @@ -28,6 +28,8 @@ import com.velocitypowered.api.proxy.Player; import de.steamwar.messages.Chatter; import de.steamwar.messages.Message; import de.steamwar.persistent.Subserver; +import de.steamwar.sql.CheckedSchematic; +import de.steamwar.sql.SchematicType; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserPerm; import de.steamwar.velocitycore.commands.*; @@ -82,6 +84,16 @@ public class ConnectionListener extends BasicListener { } } + for (CheckedSchematic checkedSchematic : CheckedSchematic.getUnseen(user)) { + SchematicType type = SchematicType.fromDB(checkedSchematic.getNodeType()); + if(type == null) continue; + if (checkedSchematic.getDeclineReason().equals("freigegeben")) { + chatter.system("CHECK_ACCEPTED", type.name(), checkedSchematic.getSchemName()); + } else { + chatter.system("CHECK_DECLINED", type.name(), checkedSchematic.getSchemName(), checkedSchematic.getDeclineReason()); + } + } + if(newPlayers.contains(player.getUniqueId())){ Chatter.broadcast().system("JOIN_FIRST", player); newPlayers.remove(player.getUniqueId()); From 4c2391598733ed7fb88e5bf63693bb68e6b23a72 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 13 Apr 2025 18:09:24 +0200 Subject: [PATCH 002/153] Use Transfer Packet for Event Velocity --- .gitignore | 6 ++- .../SQL/src/de/steamwar/sql/EventFight.java | 14 ++++++ .../steamwar/velocitycore/EventStarter.java | 9 ++++ .../commands/ServerSwitchCommand.java | 20 +++++++- .../listeners/EventModeListener.java | 48 +++++++++++++++---- 5 files changed, 87 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index e038e02a8..b0a7fe1b8 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,8 @@ bin/ .vscode # Other -lib \ No newline at end of file +lib +/WebsiteBackend/data +/WebsiteBackend/logs +/WebsiteBackend/skins +/WebsiteBackend/config.json \ No newline at end of file diff --git a/CommonCore/SQL/src/de/steamwar/sql/EventFight.java b/CommonCore/SQL/src/de/steamwar/sql/EventFight.java index fe91e3be1..29b0620a6 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/EventFight.java +++ b/CommonCore/SQL/src/de/steamwar/sql/EventFight.java @@ -39,6 +39,7 @@ public class EventFight implements Comparable { private static final SelectStatement byId = table.select(Table.PRIMARY); private static final SelectStatement allComing = new SelectStatement<>(table, "SELECT * FROM EventFight WHERE StartTime > now() ORDER BY StartTime ASC"); private static final SelectStatement event = new SelectStatement<>(table, "SELECT * FROM EventFight WHERE EventID = ? ORDER BY StartTime ASC"); + private static final SelectStatement activeFights = new SelectStatement<>(table, "SELECT * FROM EventFight WHERE Fight IS NOT NULL AND StartTime > now() AND DATEDIFF(StartTime, now()) < 0"); private static final Statement reschedule = table.update(Table.PRIMARY, "StartTime"); private static final Statement setResult = table.update(Table.PRIMARY, "Ergebnis"); private static final Statement setFight = table.update(Table.PRIMARY, "Fight"); @@ -63,6 +64,19 @@ public class EventFight implements Comparable { return event.listSelect(eventID); } + private static List activeFightsCache = null; + + public static void clearActiveFightsCache() { + activeFightsCache = null; + } + + public static List getActiveFights() { + if (activeFightsCache == null) { + activeFightsCache = activeFights.listSelect(); + } + return activeFightsCache; + } + public static EventFight create(int event, Timestamp from, String spielmodus, String map, int blueTeam, int redTeam, Integer spectatePort) { return get(create.insertGetKey(event, from, spielmodus, map, blueTeam, redTeam, spectatePort)); } diff --git a/VelocityCore/src/de/steamwar/velocitycore/EventStarter.java b/VelocityCore/src/de/steamwar/velocitycore/EventStarter.java index 15c16b64c..3095819d5 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/EventStarter.java +++ b/VelocityCore/src/de/steamwar/velocitycore/EventStarter.java @@ -23,6 +23,7 @@ import de.steamwar.messages.Chatter; import de.steamwar.messages.Message; import de.steamwar.persistent.Subserver; import de.steamwar.sql.EventFight; +import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.Team; import net.kyori.adventure.text.event.ClickEvent; @@ -68,6 +69,13 @@ public class EventStarter { starter.callback(subserver -> { eventServer.put(blue.getTeamId(), subserver); eventServer.put(red.getTeamId(), subserver); + + VelocityCore.getProxy().getAllPlayers().forEach(player -> { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if (user.getTeam() == blue.getTeamId() || user.getTeam() == red.getTeamId()) { + subserver.sendPlayer(player); + } + }); }).start(); command = "/event " + blue.getTeamKuerzel(); @@ -76,6 +84,7 @@ public class EventStarter { } Chatter.broadcast().system("EVENT_FIGHT_BROADCAST", new Message("EVENT_FIGHT_BROADCAST_HOVER"), ClickEvent.runCommand(command), blue.getTeamColor(), blue.getTeamName(), red.getTeamColor(), red.getTeamName()); } + EventFight.clearActiveFightsCache(); } private EventFight nextFight(Queue fights){ diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/ServerSwitchCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/ServerSwitchCommand.java index 142c5f56a..8cbcd01e7 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/ServerSwitchCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/ServerSwitchCommand.java @@ -19,22 +19,40 @@ package de.steamwar.velocitycore.commands; +import java.net.InetSocketAddress; +import java.util.List; + import com.velocitypowered.api.proxy.server.RegisteredServer; import de.steamwar.velocitycore.VelocityCore; import de.steamwar.command.SWCommand; import de.steamwar.messages.PlayerChatter; +import de.steamwar.sql.EventFight; +import de.steamwar.sql.SteamwarUser; public class ServerSwitchCommand extends SWCommand { private final RegisteredServer server; + private final boolean isSpectateServer; - public ServerSwitchCommand(String cmd, String name, String... aliases) { + public ServerSwitchCommand(String cmd, String name, boolean isSpectateServer, String... aliases) { super(cmd, null, aliases); server = VelocityCore.getProxy().getServer(name).orElseThrow(); + this.isSpectateServer = isSpectateServer; } @Register public void genericCommand(PlayerChatter sender) { + if (isSpectateServer) { + SteamwarUser user = SteamwarUser.get(sender.getPlayer().getUniqueId()); + List activeFights = EventFight.getActiveFights(); + + if (activeFights.stream() + .anyMatch(fight -> fight.getTeamRed() == user.getTeam() || fight.getTeamBlue() == user.getTeam())) { + sender.getPlayer().transferToHost(new InetSocketAddress("steamwar.de", 25566)); + return; + } + } + sender.getPlayer().createConnectionRequest(server).fireAndForget(); } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/EventModeListener.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/EventModeListener.java index 5cc557575..0b09ef33d 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/EventModeListener.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/EventModeListener.java @@ -19,31 +19,63 @@ package de.steamwar.velocitycore.listeners; +import java.net.InetSocketAddress; +import java.util.List; + import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.connection.PostLoginEvent; -import de.steamwar.messages.Chatter; +import com.velocitypowered.api.event.player.ServerConnectedEvent; +import com.velocitypowered.api.proxy.Player; + +import de.steamwar.persistent.Subserver; import de.steamwar.sql.Event; +import de.steamwar.sql.EventFight; import de.steamwar.sql.Referee; +import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.TeamTeilnahme; +import de.steamwar.velocitycore.EventStarter; public class EventModeListener extends BasicListener { @Subscribe public void onPostLogin(PostLoginEvent e) { - Chatter sender = Chatter.disconnect(e.getPlayer()); + Player player = e.getPlayer(); + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); Event event = Event.get(); - if(event == null) { - sender.system("EVENTMODE_KICK"); + if (event == null) { + player.transferToHost(new InetSocketAddress("steamwar.de", 25565)); return; } - if(TeamTeilnahme.nimmtTeil(sender.user().getTeam(), event.getEventID())) + if (TeamTeilnahme.nimmtTeil(user.getTeam(), event.getEventID())) { + + Subserver server = EventStarter.getEventServer().get(user.getTeam()); + + if (server != null) { + server.sendPlayer(player); + } + + return; + } + + if (Referee.get(event.getEventID()).contains(user.getId())) return; - if(Referee.get(event.getEventID()).contains(sender.user().getId())) - return; + player.transferToHost(new InetSocketAddress("steamwar.de", 25565)); + } - sender.system("EVENTMODE_KICK"); + @Subscribe + public void onLobby(ServerConnectedEvent e) { + Player player = e.getPlayer(); + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + + EventFight.clearActiveFightsCache(); + List activeFights = EventFight.getActiveFights(); + + if (activeFights.stream() + .noneMatch(fight -> fight.getTeamRed() == user.getTeam() || fight.getTeamBlue() == user.getTeam())) { + player.transferToHost(new InetSocketAddress("steamwar.de", 25565)); + } } } From 40eeb4993f88bdae3bc68ab1ad281deda743c85c Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 13 Apr 2025 20:06:38 +0200 Subject: [PATCH 003/153] Add support for cookie-based event spectating ACHTUNG: Janky! --- .../steamwar/velocitycore/EventStarter.java | 16 ++++--- .../steamwar/velocitycore/VelocityCore.java | 3 +- .../commands/ServerSwitchCommand.java | 3 +- .../listeners/ConnectionListener.java | 6 +++ .../velocitycore/listeners/CookieEvents.java | 46 +++++++++++++++++++ .../listeners/EventModeListener.java | 30 +++++++++++- 6 files changed, 94 insertions(+), 10 deletions(-) create mode 100644 VelocityCore/src/de/steamwar/velocitycore/listeners/CookieEvents.java diff --git a/VelocityCore/src/de/steamwar/velocitycore/EventStarter.java b/VelocityCore/src/de/steamwar/velocitycore/EventStarter.java index 3095819d5..0b21cef1e 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/EventStarter.java +++ b/VelocityCore/src/de/steamwar/velocitycore/EventStarter.java @@ -25,6 +25,7 @@ import de.steamwar.persistent.Subserver; import de.steamwar.sql.EventFight; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.Team; +import lombok.Getter; import net.kyori.adventure.text.event.ClickEvent; import java.sql.Timestamp; @@ -37,6 +38,7 @@ import static de.steamwar.persistent.Storage.eventServer; public class EventStarter { + @Getter private static final Map spectatePorts = new HashMap<>(); public static void addSpectateServer(int port, String command) { @@ -70,12 +72,14 @@ public class EventStarter { eventServer.put(blue.getTeamId(), subserver); eventServer.put(red.getTeamId(), subserver); - VelocityCore.getProxy().getAllPlayers().forEach(player -> { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - if (user.getTeam() == blue.getTeamId() || user.getTeam() == red.getTeamId()) { - subserver.sendPlayer(player); - } - }); + if (VelocityCore.get().getConfig().isEventmode()) { + VelocityCore.getProxy().getAllPlayers().forEach(player -> { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if (user.getTeam() == blue.getTeamId() || user.getTeam() == red.getTeamId()) { + subserver.sendPlayer(player); + } + }); + } }).start(); command = "/event " + blue.getTeamKuerzel(); diff --git a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java index 3cec098bb..404327044 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java +++ b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java @@ -217,6 +217,7 @@ public class VelocityCore implements ReloadablePlugin { new TutorialCommand(); new Broadcaster(); + new CookieEvents(); }else{ new EventModeListener(); } @@ -288,7 +289,7 @@ public class VelocityCore implements ReloadablePlugin { if(server.getSpectatePort() != 0) EventStarter.addSpectateServer(server.getSpectatePort(), cmd); - new ServerSwitchCommand(cmd, entry.getKey(), cmds.toArray(new String[0])); + new ServerSwitchCommand(cmd, entry.getKey(), server.getSpectatePort() != 0, cmds.toArray(new String[0])); } } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/ServerSwitchCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/ServerSwitchCommand.java index 8cbcd01e7..3586f150d 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/ServerSwitchCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/ServerSwitchCommand.java @@ -22,6 +22,7 @@ package de.steamwar.velocitycore.commands; import java.net.InetSocketAddress; import java.util.List; +import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.server.RegisteredServer; import de.steamwar.velocitycore.VelocityCore; import de.steamwar.command.SWCommand; @@ -42,7 +43,7 @@ public class ServerSwitchCommand extends SWCommand { @Register public void genericCommand(PlayerChatter sender) { - if (isSpectateServer) { + if (isSpectateServer && sender.getPlayer().getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_20_5)) { SteamwarUser user = SteamwarUser.get(sender.getPlayer().getUniqueId()); List activeFights = EventFight.getActiveFights(); diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java index 95edeabbe..f18288f6b 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java @@ -23,6 +23,7 @@ import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.connection.DisconnectEvent; import com.velocitypowered.api.event.connection.PostLoginEvent; import com.velocitypowered.api.event.permission.PermissionsSetupEvent; +import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.permission.Tristate; import com.velocitypowered.api.proxy.Player; import de.steamwar.messages.Chatter; @@ -30,6 +31,7 @@ import de.steamwar.messages.Message; import de.steamwar.persistent.Subserver; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserPerm; +import de.steamwar.velocitycore.EventStarter; import de.steamwar.velocitycore.commands.*; import de.steamwar.velocitycore.discord.DiscordBot; import de.steamwar.velocitycore.discord.util.DiscordRanks; @@ -88,6 +90,10 @@ public class ConnectionListener extends BasicListener { } DiscordBot.withBot(bot -> DiscordRanks.update(user)); + + if (player.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_20_5)) { + player.requestCookie(EventModeListener.EVENT_TO_SPECTATE_KEY); + } } @Subscribe diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/CookieEvents.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/CookieEvents.java new file mode 100644 index 000000000..2c319b723 --- /dev/null +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/CookieEvents.java @@ -0,0 +1,46 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 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.velocitycore.listeners; + +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.player.CookieReceiveEvent; +import com.velocitypowered.api.proxy.Player; +import de.steamwar.sql.EventFight; +import de.steamwar.sql.SteamwarUser; +import de.steamwar.velocitycore.EventStarter; +import de.steamwar.velocitycore.VelocityCore; + +public class CookieEvents extends BasicListener { + + @Subscribe + public void handleCookies(CookieReceiveEvent e) { + if (e.getOriginalKey().equals(EventModeListener.EVENT_TO_SPECTATE_KEY)) { + Player player = e.getPlayer(); + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + + EventFight.getActiveFights().stream() + .filter(fight -> fight.getTeamRed() == user.getTeam() || fight.getTeamBlue() == user.getTeam()) + .filter(fight -> fight.getSpectatePort() != 0) + .findFirst() + .flatMap(fight -> VelocityCore.getProxy().getServer(EventStarter.getSpectatePorts().get(fight.getSpectatePort()))) + .ifPresent(registeredServer -> player.createConnectionRequest(registeredServer).fireAndForget()); + } + } +} diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/EventModeListener.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/EventModeListener.java index 0b09ef33d..688f3885d 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/EventModeListener.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/EventModeListener.java @@ -20,13 +20,16 @@ package de.steamwar.velocitycore.listeners; import java.net.InetSocketAddress; +import java.nio.charset.Charset; import java.util.List; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.connection.PostLoginEvent; import com.velocitypowered.api.event.player.ServerConnectedEvent; +import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.Player; +import de.steamwar.messages.Chatter; import de.steamwar.persistent.Subserver; import de.steamwar.sql.Event; import de.steamwar.sql.EventFight; @@ -34,21 +37,35 @@ import de.steamwar.sql.Referee; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.TeamTeilnahme; import de.steamwar.velocitycore.EventStarter; +import de.steamwar.velocitycore.VelocityCore; +import net.kyori.adventure.key.Key; public class EventModeListener extends BasicListener { + public static final Key EVENT_TO_SPECTATE_KEY = Key.key("sw", "event_to_spectate"); + @Subscribe public void onPostLogin(PostLoginEvent e) { Player player = e.getPlayer(); SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + Chatter sender = Chatter.disconnect(player); Event event = Event.get(); if (event == null) { - player.transferToHost(new InetSocketAddress("steamwar.de", 25565)); + if (player.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_20_5)) { + sender.system("EVENTMODE_KICK"); + } else { + player.transferToHost(new InetSocketAddress("steamwar.de", 25565)); + } return; } if (TeamTeilnahme.nimmtTeil(user.getTeam(), event.getEventID())) { + if (player.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_20_5) && VelocityCore.getProxy().getAllPlayers().stream().map(p -> SteamwarUser.get(p.getUniqueId())).filter(u -> u.getTeam() == user.getTeam()).count() > event.getMaximumTeamMembers()) { + player.storeCookie(EVENT_TO_SPECTATE_KEY, "TRUE".getBytes()); + player.transferToHost(new InetSocketAddress("steamwar.de", 25565)); + return; + } Subserver server = EventStarter.getEventServer().get(user.getTeam()); @@ -62,12 +79,21 @@ public class EventModeListener extends BasicListener { if (Referee.get(event.getEventID()).contains(user.getId())) return; - player.transferToHost(new InetSocketAddress("steamwar.de", 25565)); + if (player.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_20_5)) { + sender.system("EVENTMODE_KICK"); + } else { + player.transferToHost(new InetSocketAddress("steamwar.de", 25565)); + } } @Subscribe public void onLobby(ServerConnectedEvent e) { Player player = e.getPlayer(); + + if (player.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_20_5)) { + return; + } + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); EventFight.clearActiveFightsCache(); From bb97d80c18db39cd2b0e05c0bbf068ebe7e9f682 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 24 Apr 2025 13:10:48 +0200 Subject: [PATCH 004/153] Refactor to align with Minecraft 1.21.5 API changes --- .../bausystem/utils/NMSWrapper21.java | 100 ++++++++---------- .../utils/CraftbukkitWrapper21.java | 2 +- .../de/steamwar/core/BountifulWrapper21.java | 4 +- .../src/de/steamwar/core/ChatWrapper21.java | 16 +-- .../steamwar/core/CraftbukkitWrapper21.java | 10 +- settings.gradle.kts | 4 +- 6 files changed, 63 insertions(+), 73 deletions(-) diff --git a/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NMSWrapper21.java b/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NMSWrapper21.java index e6308e431..8d59ffa98 100644 --- a/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NMSWrapper21.java +++ b/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NMSWrapper21.java @@ -21,41 +21,39 @@ package de.steamwar.bausystem.utils; import de.steamwar.Reflection; import de.steamwar.bausystem.features.util.NoClipCommand; -import net.minecraft.core.component.DataComponents; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.network.protocol.game.PacketPlayInSetCreativeSlot; -import net.minecraft.network.protocol.game.PacketPlayOutExplosion; -import net.minecraft.network.protocol.game.PacketPlayOutGameStateChange; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.server.level.PlayerInteractManager; -import net.minecraft.world.entity.player.EntityHuman; -import net.minecraft.world.entity.player.PlayerAbilities; -import net.minecraft.world.item.component.CustomData; -import net.minecraft.world.level.EnumGamemode; +import io.papermc.paper.datacomponent.DataComponentTypes; +import io.papermc.paper.datacomponent.item.ItemContainerContents; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundExplodePacket; +import net.minecraft.network.protocol.game.ClientboundGameEventPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.level.ServerPlayerGameMode; +import net.minecraft.world.entity.player.Abilities; +import net.minecraft.world.level.GameType; import org.bukkit.GameMode; import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_21_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_21_R2.inventory.CraftItemStack; +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerGameModeChangeEvent; import org.bukkit.inventory.ItemStack; +import java.util.List; import java.util.Optional; public class NMSWrapper21 implements NMSWrapper { - private static final Reflection.Field playerInteractManager = Reflection.getField(EntityPlayer.class, null, PlayerInteractManager.class); + private static final Reflection.Field playerInteractManager = Reflection.getField(ServerPlayer.class, null, ServerPlayerGameMode.class); @Override public void setInternalGameMode(Player player, GameMode gameMode) { - playerInteractManager.get(((CraftPlayer) player).getHandle()).a(EnumGamemode.a(gameMode.getValue())); + playerInteractManager.get(((CraftPlayer) player).getHandle()).changeGameModeForPlayer(GameType.byId(gameMode.getValue()), PlayerGameModeChangeEvent.Cause.UNKNOWN, null); } @Override public void setSlotToItemStack(Player player, Object o) { - PacketPlayInSetCreativeSlot packetPlayInSetCreativeSlot = (PacketPlayInSetCreativeSlot) o; - int index = packetPlayInSetCreativeSlot.b(); + ClientboundContainerSetSlotPacket packetPlayInSetCreativeSlot = (ClientboundContainerSetSlotPacket) o; + int index = packetPlayInSetCreativeSlot.getSlot(); if (index >= 36 && index <= 44) { index -= 36; } else if (index > 44) { @@ -63,25 +61,23 @@ public class NMSWrapper21 implements NMSWrapper { } else if (index <= 8) { index = index - 8 + 36; } - player.getInventory().setItem(index, CraftItemStack.asBukkitCopy(packetPlayInSetCreativeSlot.e())); + player.getInventory().setItem(index, CraftItemStack.asBukkitCopy(packetPlayInSetCreativeSlot.getItem())); if (index < 9) player.getInventory().setHeldItemSlot(index); player.updateInventory(); } - private static final Reflection.Field gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12); + private static final Reflection.Field gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, ClientboundGameEventPacket.Type.class, 12); @Override public void setGameStateChangeReason(Object packet) { - gameStateChangeReason.set(packet, PacketPlayOutGameStateChange.d); + gameStateChangeReason.set(packet, ClientboundGameEventPacket.CHANGE_GAME_MODE); } - private static final Reflection.Field playerAbilities = Reflection.getField(EntityHuman.class, null, PlayerAbilities.class); - @Override public void setPlayerBuildAbilities(Player player) { - PlayerAbilities abilities = playerAbilities.get(((CraftPlayer) player).getHandle()); - abilities.d = true; - abilities.e = true; + Abilities abilities = (((CraftPlayer) player).getHandle()).getAbilities(); + abilities.mayBuild = true; + abilities.mayfly = true; } @Override @@ -93,49 +89,45 @@ public class NMSWrapper21 implements NMSWrapper { @Override public boolean checkItemStack(ItemStack item) { - net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(item); - NBTTagCompound tag = nmsItem.a(DataComponents.b, CustomData.a).c(); - if (tag.e("BlockEntityTag")) { - NBTTagCompound blockTag = tag.p("BlockEntityTag"); - if (blockTag.e("Items")) { - return drillDown(blockTag.c("Items", 10), 0, 0) > threshold; - } + ItemContainerContents data = item.getData(DataComponentTypes.CONTAINER); + if (data == null) { + return false; } - return false; + return drillDown(data.contents(), 0, 0) <= threshold; } - private int drillDown(NBTTagList items, int layer, int start) { + private int drillDown(List items, int layer, int start) { if (layer > 2) return start + threshold; int invalid = start; - for (NBTBase nbtBase : items) { - if (!(nbtBase instanceof NBTTagCompound slot)) + for (int i = start; i < items.size(); i++) { + ItemStack item = items.get(i); + if (item.isEmpty()) continue; + + invalid += item.getAmount(); + + ItemContainerContents data = item.getData(DataComponentTypes.CONTAINER); + if (data == null) { continue; - if (slot.e("tag")) { - invalid += slot.f("Count"); - NBTTagCompound iTag = slot.p("tag"); - if (iTag.e("BlockEntityTag")) { - NBTTagCompound blockTag = iTag.p("BlockEntityTag"); - if (blockTag.e("Items")) { - invalid = drillDown(blockTag.c("Items", 10), layer + 1, invalid); - } - } } - if (invalid > threshold) - break; + + List subItems = data.contents(); + if (subItems.size() > 1) { + invalid = drillDown(subItems, layer + 1, invalid); + } } return invalid; } @Override public Object resetExplosionKnockback(Object packet) { - PacketPlayOutExplosion explosion = (PacketPlayOutExplosion) packet; + ClientboundExplodePacket explosion = (ClientboundExplodePacket) packet; - return new PacketPlayOutExplosion( - explosion.b(), + return new ClientboundExplodePacket( + explosion.center(), Optional.empty(), - explosion.f(), - explosion.g() + explosion.explosionParticle(), + explosion.explosionSound() ); } } diff --git a/FightSystem/FightSystem_21/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper21.java b/FightSystem/FightSystem_21/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper21.java index 9e52bb368..b5c920a77 100644 --- a/FightSystem/FightSystem_21/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper21.java +++ b/FightSystem/FightSystem_21/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper21.java @@ -25,6 +25,6 @@ public class CraftbukkitWrapper21 extends CraftbukkitWrapper18 { @Override public float headRotation(Entity e) { - return getEntity(e).bS(); + return getEntity(e).getYHeadRot(); } } diff --git a/SpigotCore/SpigotCore_21/src/de/steamwar/core/BountifulWrapper21.java b/SpigotCore/SpigotCore_21/src/de/steamwar/core/BountifulWrapper21.java index e01a06fcf..be404e30f 100644 --- a/SpigotCore/SpigotCore_21/src/de/steamwar/core/BountifulWrapper21.java +++ b/SpigotCore/SpigotCore_21/src/de/steamwar/core/BountifulWrapper21.java @@ -21,7 +21,7 @@ package de.steamwar.core; import de.steamwar.Reflection; import net.minecraft.world.entity.PositionMoveRotation; -import net.minecraft.world.phys.Vec3D; +import net.minecraft.world.phys.Vec3; public class BountifulWrapper21 extends BountifulWrapper9 { @@ -33,7 +33,7 @@ public class BountifulWrapper21 extends BountifulWrapper9 { return (packet, x, y, z, pitch, yaw) -> { PositionMoveRotation pos = field.get(packet); - field.set(packet, new PositionMoveRotation(new Vec3D(x, y, z), pos.b(), yaw, pitch)); + field.set(packet, new PositionMoveRotation(new Vec3(x, y, z), pos.deltaMovement(), yaw, pitch)); }; } catch (IllegalArgumentException e) { return super.getPositionSetter(packetClass, fieldOffset); diff --git a/SpigotCore/SpigotCore_21/src/de/steamwar/core/ChatWrapper21.java b/SpigotCore/SpigotCore_21/src/de/steamwar/core/ChatWrapper21.java index 760ba3934..64757bbec 100644 --- a/SpigotCore/SpigotCore_21/src/de/steamwar/core/ChatWrapper21.java +++ b/SpigotCore/SpigotCore_21/src/de/steamwar/core/ChatWrapper21.java @@ -19,26 +19,26 @@ package de.steamwar.core; -import net.minecraft.network.chat.IChatMutableComponent; -import net.minecraft.network.chat.contents.LiteralContents; -import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata; -import net.minecraft.network.syncher.DataWatcher; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.contents.PlainTextContents; +import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; +import net.minecraft.network.syncher.SynchedEntityData; import java.util.ArrayList; public class ChatWrapper21 implements ChatWrapper { @Override public Object stringToChatComponent(String text) { - return IChatMutableComponent.a(LiteralContents.a(text)); + return MutableComponent.create(PlainTextContents.create(text)); } @Override public Object getDataWatcherPacket(int entityId, Object... dataWatcherKeyValues) { - ArrayList> nativeWatchers = new ArrayList<>(1); + ArrayList> nativeWatchers = new ArrayList<>(1); for(int i = 0; i < dataWatcherKeyValues.length; i+=2) { - nativeWatchers.add(((DataWatcher.Item) BountifulWrapper.impl.getDataWatcherItem(dataWatcherKeyValues[i], dataWatcherKeyValues[i+1])).e()); + nativeWatchers.add(((SynchedEntityData.DataItem) BountifulWrapper.impl.getDataWatcherItem(dataWatcherKeyValues[i], dataWatcherKeyValues[i+1])).value()); } - return new PacketPlayOutEntityMetadata(entityId, nativeWatchers); + return new ClientboundSetEntityDataPacket(entityId, nativeWatchers); } } diff --git a/SpigotCore/SpigotCore_21/src/de/steamwar/core/CraftbukkitWrapper21.java b/SpigotCore/SpigotCore_21/src/de/steamwar/core/CraftbukkitWrapper21.java index 337ee1db5..a774c4016 100644 --- a/SpigotCore/SpigotCore_21/src/de/steamwar/core/CraftbukkitWrapper21.java +++ b/SpigotCore/SpigotCore_21/src/de/steamwar/core/CraftbukkitWrapper21.java @@ -22,20 +22,18 @@ package de.steamwar.core; import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; -import net.minecraft.world.level.World; -import net.minecraft.world.level.chunk.Chunk; +import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.chunk.status.ChunkStatus; -import net.minecraft.world.level.lighting.LevelLightEngine; +import org.bukkit.craftbukkit.CraftChunk; import org.bukkit.entity.Player; public class CraftbukkitWrapper21 implements CraftbukkitWrapper.ICraftbukkitWrapper { private static final Reflection.Method getHandle = Reflection.getMethod("org.bukkit.craftbukkit.CraftChunk", "getHandle", ChunkStatus.class); - private static final Reflection.Method getLightEngine = Reflection.getTypedMethod(World.class, null, LevelLightEngine.class); @Override public void sendChunk(Player p, int chunkX, int chunkZ) { - Chunk chunk = (Chunk) getHandle.invoke(p.getWorld().getChunkAt(chunkX, chunkZ), ChunkStatus.n); - TinyProtocol.instance.sendPacket(p, new ClientboundLevelChunkWithLightPacket(chunk, (LevelLightEngine) getLightEngine.invoke(chunk.r), null, null, true)); + LevelChunk chunk = (LevelChunk) ((CraftChunk) p.getWorld().getChunkAt(chunkX, chunkZ)).getHandle(ChunkStatus.FULL); + TinyProtocol.instance.sendPacket(p, new ClientboundLevelChunkWithLightPacket(chunk, chunk.level.getLightEngine(), null, null, true)); } } diff --git a/settings.gradle.kts b/settings.gradle.kts index dc94bc0cc..80f9aac7f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -111,7 +111,7 @@ dependencyResolutionManagement { library("spigotapi", "org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT") library("spigotannotations", "org.spigotmc:plugin-annotations:1.2.3-SNAPSHOT") library("paperapi", "io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT") - library("paperapi21", "io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT") + library("paperapi21", "io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT") library("authlib", "com.mojang:authlib:1.5.25") library("datafixer", "com.mojang:datafixerupper:4.0.26") library("brigadier", "com.mojang:brigadier:1.0.18") @@ -126,7 +126,7 @@ dependencyResolutionManagement { library("nms18", "de.steamwar:spigot:1.18") library("nms19", "de.steamwar:spigot:1.19") library("nms20", "de.steamwar:spigot:1.20") - library("nms21", "de.steamwar:spigot:1.21") + library("nms21", "de.steamwar:spigot:1.21.5") library("axiom", "de.steamwar:axiompaper:RELEASE") library("worldedit12", "de.steamwar:worldedit:1.12") From aeff16b7dd1e0d7d01fad1b4f54b1229f84013df Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 24 Apr 2025 14:07:35 +0200 Subject: [PATCH 005/153] Update to support Minecraft 1.21.5 version --- VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java b/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java index a5e08b55d..63d15da79 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java @@ -44,14 +44,14 @@ public enum ServerVersion { PAPER_18("paper-1.18.2.jar", 15, ProtocolVersion.MINECRAFT_1_18_2), PAPER_19("paper-1.19.3.jar", 19, ProtocolVersion.MINECRAFT_1_19_3), PAPER_20("paper-1.20.1.jar", 20, ProtocolVersion.MINECRAFT_1_20), - PAPER_21("paper-1.21.3.jar", 21, ProtocolVersion.MINECRAFT_1_21_2); + PAPER_21("paper-1.21.5.jar", 21, ProtocolVersion.MINECRAFT_1_21_5); private static final Map chatMap = new HashMap<>(); static { chatMap.put("21", ServerVersion.PAPER_21); chatMap.put("1.21", ServerVersion.PAPER_21); - chatMap.put("1.21.3", ServerVersion.PAPER_21); + chatMap.put("1.21.5", ServerVersion.PAPER_21); chatMap.put("20", ServerVersion.PAPER_20); chatMap.put("1.20", ServerVersion.PAPER_20); From 7e863e806223c889e529e1de447ae9ebd7916951 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 27 Apr 2025 02:53:59 +0200 Subject: [PATCH 006/153] Refactor entity field access with version-aware adjustments --- .../src/de/steamwar/core/BountifulWrapper9.java | 11 ++++++----- .../SpigotCore_Main/src/de/steamwar/Reflection.java | 1 + .../src/de/steamwar/entity/REntityServer.java | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java index ce7f6170e..156662a8f 100644 --- a/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java +++ b/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java @@ -85,11 +85,12 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { @Override public BountifulWrapper.PositionSetter getRelMoveSetter(Class packetClass) { Class type = Core.getVersion() > 12 ? short.class : int.class; - Reflection.Field moveX = Reflection.getField(packetClass, "b", type); - Reflection.Field moveY = Reflection.getField(packetClass, "c", type); - Reflection.Field moveZ = Reflection.getField(packetClass, "d", type); - Reflection.Field moveYaw = Reflection.getField(packetClass, "e", byte.class); - Reflection.Field movePitch = Reflection.getField(packetClass, "f", byte.class); + int fieldOffset = Core.getVersion() > 12 ? 0 : 1; + Reflection.Field moveX = Reflection.getField(packetClass, type, 0 + fieldOffset); + Reflection.Field moveY = Reflection.getField(packetClass, type, 1 + fieldOffset); + Reflection.Field moveZ = Reflection.getField(packetClass, type, 2 + fieldOffset); + Reflection.Field moveYaw = Reflection.getField(packetClass, byte.class, 0); + Reflection.Field movePitch = Reflection.getField(packetClass, byte.class, 1); return (packet, x, y, z, pitch, yaw) -> { moveX.set(packet, (short)(x*4096)); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java index 92e3d3fdf..86dca0bf8 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java @@ -94,6 +94,7 @@ public final class Reflection { spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundContainerClickPacket", "net.minecraft.network.protocol.game.PacketPlayInWindowClick"); spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundInteractPacket", "net.minecraft.network.protocol.game.PacketPlayInUseEntity"); spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundInteractPacket$Action", "net.minecraft.network.protocol.game.PacketPlayInUseEntity$EnumEntityUseAction"); + spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundInteractPacket$ActionType", "net.minecraft.network.protocol.game.PacketPlayInUseEntity$b"); spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos", "net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPosition"); spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot", "net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPositionLook"); spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Rot", "net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInLook"); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index d5ced5500..9296fc767 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -50,11 +50,12 @@ public class REntityServer implements Listener { private static final Class useEntity = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket"); private static final Reflection.Field useEntityTarget = Reflection.getField(useEntity, int.class, 0); private static final Class useEntityEnumAction = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket$Action"); + private static final Class useEntityEnumActionType = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket$ActionType"); private static final Reflection.Field useEntityAction = Reflection.getField(useEntity, useEntityEnumAction, 0); private static final Function getEntityAction; static { if(Core.getVersion() > 15) { - Reflection.Method useEntityGetAction = Reflection.getMethod(useEntityEnumAction, "a"); + Reflection.Method useEntityGetAction = Reflection.getTypedMethod(useEntityEnumAction, null, useEntityEnumActionType); getEntityAction = value -> ((Enum) useEntityGetAction.invoke(value)).ordinal(); } else { getEntityAction = value -> ((Enum) value).ordinal(); From f30c3b2f34f324caa17a30d9eb638f8f4b963a44 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 27 Apr 2025 02:58:05 +0200 Subject: [PATCH 007/153] Update anvilgui library to version 1.10.5-SNAPSHOT --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 80f9aac7f..51e7db6ae 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -115,7 +115,7 @@ dependencyResolutionManagement { library("authlib", "com.mojang:authlib:1.5.25") library("datafixer", "com.mojang:datafixerupper:4.0.26") library("brigadier", "com.mojang:brigadier:1.0.18") - library("anvilgui", "net.wesjd:anvilgui:1.10.3-SNAPSHOT") + library("anvilgui", "net.wesjd:anvilgui:1.10.5-SNAPSHOT") library("nms8", "de.steamwar:spigot:1.8") library("nms9", "de.steamwar:spigot:1.9") From 1912ad52e47bac784a71d42680aa5792cf13e4c1 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 28 Apr 2025 23:25:36 +0200 Subject: [PATCH 008/153] Add protocol version check to handle potential packet issue --- .../src/de/steamwar/velocitycore/tablist/Tablist.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java b/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java index 6195bd739..26835f8e2 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java +++ b/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java @@ -148,6 +148,11 @@ public class Tablist extends ChannelInboundHandlerAdapter { current.clear(); } + if (player.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_21_5)) { + // TODO: Misformed Packet? + return; + } + sendPacket(player, createTeamPacket); } } From f387805b4023c27f5f6f51e13e61caaaf5176830 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 7 May 2025 13:51:13 +0200 Subject: [PATCH 009/153] Add event grouping --- .../SQL/src/de/steamwar/sql/EventFight.java | 23 +++ .../SQL/src/de/steamwar/sql/EventGroup.java | 117 +++++++++++++++ .../src/de/steamwar/sql/EventRelation.java | 133 ++++++++++++++++++ 3 files changed, 273 insertions(+) create mode 100644 CommonCore/SQL/src/de/steamwar/sql/EventGroup.java create mode 100644 CommonCore/SQL/src/de/steamwar/sql/EventRelation.java diff --git a/CommonCore/SQL/src/de/steamwar/sql/EventFight.java b/CommonCore/SQL/src/de/steamwar/sql/EventFight.java index fe91e3be1..c595149b2 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/EventFight.java +++ b/CommonCore/SQL/src/de/steamwar/sql/EventFight.java @@ -37,6 +37,7 @@ public class EventFight implements Comparable { private static final Table table = new Table<>(EventFight.class); private static final SelectStatement byId = table.select(Table.PRIMARY); + private static final SelectStatement byGroup = new SelectStatement(table, "SELECT * FROM EventFight WHERE GroupID = ? ORDER BY StartTime ASC"); private static final SelectStatement allComing = new SelectStatement<>(table, "SELECT * FROM EventFight WHERE StartTime > now() ORDER BY StartTime ASC"); private static final SelectStatement event = new SelectStatement<>(table, "SELECT * FROM EventFight WHERE EventID = ? ORDER BY StartTime ASC"); private static final Statement reschedule = table.update(Table.PRIMARY, "StartTime"); @@ -54,6 +55,10 @@ public class EventFight implements Comparable { return byId.select(fightID); } + public static List get(EventGroup group) { + return byGroup.listSelect(group.getId()); + } + public static void loadAllComingFights() { fights.clear(); fights.addAll(allComing.listSelect()); @@ -75,6 +80,10 @@ public class EventFight implements Comparable { private final int fightID; @Getter @Setter + @Field(nullable = true, def = "null") + private Integer groupId; + @Getter + @Setter @Field private Timestamp startTime; @Getter @@ -98,11 +107,25 @@ public class EventFight implements Comparable { @Field(nullable = true) private Integer spectatePort; @Getter + @Setter + @Field(def = "1") + private int bestOf; + @Getter @Field(def = "0") private int ergebnis; @Field(nullable = true) private int fight; + public Optional getGroup() { + return Optional.ofNullable(groupId).flatMap(EventGroup::get); + } + + public Optional getWinner() { + if(ergebnis == 0) + return Optional.empty(); + return Optional.ofNullable(ergebnis == 1 ? Team.get(teamBlue) : Team.get(teamRed)); + } + public void setErgebnis(int winner) { this.ergebnis = winner; setResult.update(winner, fightID); diff --git a/CommonCore/SQL/src/de/steamwar/sql/EventGroup.java b/CommonCore/SQL/src/de/steamwar/sql/EventGroup.java new file mode 100644 index 000000000..3ea62738e --- /dev/null +++ b/CommonCore/SQL/src/de/steamwar/sql/EventGroup.java @@ -0,0 +1,117 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 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.sql; + +import de.steamwar.sql.internal.Field; +import de.steamwar.sql.internal.SelectStatement; +import de.steamwar.sql.internal.SqlTypeMapper; +import de.steamwar.sql.internal.Table; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +@AllArgsConstructor +@Getter +@Setter +public class EventGroup { + static { + SqlTypeMapper.ordinalEnumMapper(EventGroupType.class); + } + + private static final Table table = new Table<>(EventGroup.class); + + private static final SelectStatement get = table.select(Table.PRIMARY); + private static final SelectStatement byEvent = new SelectStatement<>(table, "SELECT * FROM EventGroup WHERE EventID = ?"); + + public static List get(Event eventID) { + return byEvent.listSelect(eventID); + } + + public static Optional get(int id) { + return Optional.ofNullable(get.select(id)); + } + + @Field(keys = Table.PRIMARY) + private final int id; + + @Field + private String name; + + @Field + private EventGroupType type; + + @Field + private int pointsPerWin; + + @Field + private int pointsPerLoss; + + @Field + private int pointsPerDraw; + + public List getFights() { + return EventFight.get(this); + } + + public Map calculatePoints() { + Map teams = new HashMap<>(); + Map points = new HashMap<>(); + + for(EventFight fight : getFights()) { + int blueTeamAdd = 0; + int redTeamAdd = 0; + + switch (fight.getErgebnis()) { + case 1: + blueTeamAdd += pointsPerWin; + redTeamAdd += pointsPerLoss; + break; + case 2: + blueTeamAdd += pointsPerLoss; + redTeamAdd += pointsPerWin; + break; + case 0: + if (fight.getFightID() != 0) { + blueTeamAdd += pointsPerDraw; + redTeamAdd += pointsPerDraw; + } + break; + } + + Team blueTeam = teams.computeIfAbsent(fight.getTeamBlue(), Team::get); + Team redTeam = teams.computeIfAbsent(fight.getTeamRed(), Team::get); + + points.put(blueTeam, points.getOrDefault(blueTeam, 0) + blueTeamAdd); + points.put(redTeam, points.getOrDefault(redTeam, 0) + redTeamAdd); + } + + return points; + } + + public static enum EventGroupType { + GROUP_STAGE, + ELIMINATION_STAGE + } +} diff --git a/CommonCore/SQL/src/de/steamwar/sql/EventRelation.java b/CommonCore/SQL/src/de/steamwar/sql/EventRelation.java new file mode 100644 index 000000000..1c154d561 --- /dev/null +++ b/CommonCore/SQL/src/de/steamwar/sql/EventRelation.java @@ -0,0 +1,133 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 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.sql; + +import de.steamwar.sql.internal.Field; +import de.steamwar.sql.internal.SqlTypeMapper; +import de.steamwar.sql.internal.Table; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +import java.util.Map; +import java.util.Optional; + +@AllArgsConstructor +@Getter +@Setter +public class EventRelation { + + static { + SqlTypeMapper.ordinalEnumMapper(FightTeam.class); + SqlTypeMapper.ordinalEnumMapper(FromType.class); + } + + private static final Table table = new Table<>(EventRelation.class); + + @Field(keys = Table.PRIMARY) + private final int id; + + @Field + private int fightId; + + @Field + private FightTeam fightTeam; + + @Field + private FromType fromType; + + @Field + private int fromId; + + @Field + private int fromPlace; + + public EventFight getFight() { + return EventFight.get(fightId); + } + + public Optional getFromFight() { + if(fromType == FromType.FIGHT) { + return Optional.of(EventFight.get(fromId)); + } else { + return Optional.empty(); + } + } + + public Optional getFromGroup() { + if(fromType == FromType.GROUP) { + return EventGroup.get(fromId); + } else { + return Optional.empty(); + } + } + + public Optional getAdvancingTeam() { + if (fromType == FromType.FIGHT) { + return getFromFight().flatMap(EventFight::getWinner); + } else if (fromType == FromType.GROUP) { + return getFromGroup().map(EventGroup::calculatePoints) + .flatMap(points -> points.entrySet().stream() + .max(Map.Entry.comparingByValue()) + .map(Map.Entry::getKey)); + } else { + return Optional.empty(); + } + } + + public boolean apply() { + Optional team = getAdvancingTeam().map(Team::getTeamId); + if(!team.isPresent()) + return false; + + EventFight fight = getFight(); + if(fightTeam == FightTeam.RED) { + fight.update( + fight.getStartTime(), + fight.getSpielmodus(), + fight.getMap(), + team.get(), + fight.getTeamBlue(), + fight.getSpectatePort() + ); + } else { + fight.update( + fight.getStartTime(), + fight.getSpielmodus(), + fight.getMap(), + fight.getTeamRed(), + team.get(), + fight.getSpectatePort() + ); + } + + return true; + } + + public static enum FightTeam { + RED, + BLUE + } + + public static enum FromType { + FIGHT, + GROUP + } +} From c633694222734855660cdc947c85ee12153099b6 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 7 May 2025 16:16:36 +0200 Subject: [PATCH 010/153] Refactor event handling and tie-break logic implementation Introduced new methods and structures in EventGroup, EventRelation, and EventFight to streamline point calculations, tie-break detection, and dependency resolution. Improved modularity by adding methods like getLastFight, needsTieBreak, and getDependents while optimizing the event result setting process. This refactor enhances clarity, reduces redundancy, and supports better maintainability of event-related logic. --- .../SQL/src/de/steamwar/sql/EventFight.java | 15 +++++ .../SQL/src/de/steamwar/sql/EventGroup.java | 67 ++++++++++++------- .../src/de/steamwar/sql/EventRelation.java | 59 ++++++++++++++-- .../fightsystem/utils/FightStatistics.java | 17 ++++- 4 files changed, 125 insertions(+), 33 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/EventFight.java b/CommonCore/SQL/src/de/steamwar/sql/EventFight.java index c595149b2..e231fc70d 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/EventFight.java +++ b/CommonCore/SQL/src/de/steamwar/sql/EventFight.java @@ -38,6 +38,7 @@ public class EventFight implements Comparable { private static final Table table = new Table<>(EventFight.class); private static final SelectStatement byId = table.select(Table.PRIMARY); private static final SelectStatement byGroup = new SelectStatement(table, "SELECT * FROM EventFight WHERE GroupID = ? ORDER BY StartTime ASC"); + private static final SelectStatement byGroupLast = new SelectStatement(table, "SELECT * FROM EventFight WHERE GroupID = ? ORDER BY StartTime DESC LIMIT 1"); private static final SelectStatement allComing = new SelectStatement<>(table, "SELECT * FROM EventFight WHERE StartTime > now() ORDER BY StartTime ASC"); private static final SelectStatement event = new SelectStatement<>(table, "SELECT * FROM EventFight WHERE EventID = ? ORDER BY StartTime ASC"); private static final Statement reschedule = table.update(Table.PRIMARY, "StartTime"); @@ -59,6 +60,10 @@ public class EventFight implements Comparable { return byGroup.listSelect(group.getId()); } + public static Optional getLast(EventGroup group) { + return Optional.ofNullable(byGroupLast.select(group.getId())); + } + public static void loadAllComingFights() { fights.clear(); fights.addAll(allComing.listSelect()); @@ -126,6 +131,16 @@ public class EventFight implements Comparable { return Optional.ofNullable(ergebnis == 1 ? Team.get(teamBlue) : Team.get(teamRed)); } + public Optional getLosser() { + if(ergebnis == 0) + return Optional.empty(); + return Optional.ofNullable(ergebnis == 1 ? Team.get(teamRed) : Team.get(teamBlue)); + } + + public List getDependents() { + return EventRelation.getFightRelations(this); + } + public void setErgebnis(int winner) { this.ergebnis = winner; setResult.update(winner, fightID); diff --git a/CommonCore/SQL/src/de/steamwar/sql/EventGroup.java b/CommonCore/SQL/src/de/steamwar/sql/EventGroup.java index 3ea62738e..c5c005800 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/EventGroup.java +++ b/CommonCore/SQL/src/de/steamwar/sql/EventGroup.java @@ -71,45 +71,60 @@ public class EventGroup { @Field private int pointsPerDraw; + private Map points; + public List getFights() { return EventFight.get(this); } + public Optional getLastFight() { + return EventFight.getLast(this); + } + + public List getDependents() { + return EventRelation.getGroupRelations(this); + } + public Map calculatePoints() { - Map teams = new HashMap<>(); - Map points = new HashMap<>(); + if (points == null) { + Map teams = new HashMap<>(); - for(EventFight fight : getFights()) { - int blueTeamAdd = 0; - int redTeamAdd = 0; + for(EventFight fight : getFights()) { + int blueTeamAdd = 0; + int redTeamAdd = 0; - switch (fight.getErgebnis()) { - case 1: - blueTeamAdd += pointsPerWin; - redTeamAdd += pointsPerLoss; - break; - case 2: - blueTeamAdd += pointsPerLoss; - redTeamAdd += pointsPerWin; - break; - case 0: - if (fight.getFightID() != 0) { - blueTeamAdd += pointsPerDraw; - redTeamAdd += pointsPerDraw; - } - break; + switch (fight.getErgebnis()) { + case 1: + blueTeamAdd += pointsPerWin; + redTeamAdd += pointsPerLoss; + break; + case 2: + blueTeamAdd += pointsPerLoss; + redTeamAdd += pointsPerWin; + break; + case 0: + if (fight.getFightID() != 0) { + blueTeamAdd += pointsPerDraw; + redTeamAdd += pointsPerDraw; + } + break; + } + + Team blueTeam = teams.computeIfAbsent(fight.getTeamBlue(), Team::get); + Team redTeam = teams.computeIfAbsent(fight.getTeamRed(), Team::get); + + points.put(blueTeam, points.getOrDefault(blueTeam, 0) + blueTeamAdd); + points.put(redTeam, points.getOrDefault(redTeam, 0) + redTeamAdd); } - - Team blueTeam = teams.computeIfAbsent(fight.getTeamBlue(), Team::get); - Team redTeam = teams.computeIfAbsent(fight.getTeamRed(), Team::get); - - points.put(blueTeam, points.getOrDefault(blueTeam, 0) + blueTeamAdd); - points.put(redTeam, points.getOrDefault(redTeam, 0) + redTeamAdd); } return points; } + public boolean needsTieBreak() { + return calculatePoints().values().stream().sorted().limit(2).distinct().count() < 2; + } + public static enum EventGroupType { GROUP_STAGE, ELIMINATION_STAGE diff --git a/CommonCore/SQL/src/de/steamwar/sql/EventRelation.java b/CommonCore/SQL/src/de/steamwar/sql/EventRelation.java index 1c154d561..13b35f021 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/EventRelation.java +++ b/CommonCore/SQL/src/de/steamwar/sql/EventRelation.java @@ -19,13 +19,12 @@ package de.steamwar.sql; -import de.steamwar.sql.internal.Field; -import de.steamwar.sql.internal.SqlTypeMapper; -import de.steamwar.sql.internal.Table; +import de.steamwar.sql.internal.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; +import java.util.List; import java.util.Map; import java.util.Optional; @@ -41,6 +40,30 @@ public class EventRelation { private static final Table table = new Table<>(EventRelation.class); + private static final SelectStatement get = new SelectStatement<>(table, "SELECT * FROM EventRelation WHERE FromType = ? AND FromId = ?"); + private static final SelectStatement byId = new SelectStatement<>(table, "SELECT * FROM EventRelation WHERE id = ?"); + private static final Statement insert = table.insertAll(true); + private static final Statement update = table.update(Table.PRIMARY, "fromType", "fromId", "fromPlace"); + private static final Statement updateTeam = table.update(Table.PRIMARY, "fightTeam"); + private static final Statement delete = table.delete(Table.PRIMARY); + + public static EventRelation get(int id) { + return byId.select(id); + } + + public static List getFightRelations(EventFight fight) { + return get.listSelect(FromType.FIGHT, fight.getFightID()); + } + + public static List getGroupRelations(EventGroup group) { + return get.listSelect(FromType.GROUP, group.getId()); + } + + public static EventRelation create(EventFight fight, FightTeam fightTeam, FromType fromType, int fromId, int fromPlace) { + int id = insert.insertGetKey(fight.getFightID(), fightTeam, fromType, fromId, fromPlace); + return get(id); + } + @Field(keys = Table.PRIMARY) private final int id; @@ -79,9 +102,37 @@ public class EventRelation { } } + public void delete() { + delete.update(id); + } + + public void setUpdateTeam(FightTeam team) { + updateTeam.update(id, team); + this.fightTeam = team; + } + + public void setFromFight(EventFight fight, int place) { + setFrom(fight.getFightID(), place, FromType.FIGHT); + } + + public void setFromGroup(EventGroup group, int place) { + setFrom(group.getId(), place, FromType.GROUP); + } + + private void setFrom(int id, int place, FromType type) { + update.update(id, type, id, place); + this.fromType = type; + this.fromId = id; + this.fromPlace = place; + } + public Optional getAdvancingTeam() { if (fromType == FromType.FIGHT) { - return getFromFight().flatMap(EventFight::getWinner); + if (fromPlace == 1) { + return getFromFight().flatMap(EventFight::getWinner); + } else { + return getFromFight().flatMap(EventFight::getLosser); + } } else if (fromType == FromType.GROUP) { return getFromGroup().map(EventGroup::calculatePoints) .flatMap(points -> points.entrySet().stream() diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java index ae9a56ac0..3d6c5cacf 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -33,6 +33,8 @@ import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.winconditions.Wincondition; import de.steamwar.network.NetworkSender; import de.steamwar.network.packets.common.FightEndsPacket; +import de.steamwar.sql.EventFight; +import de.steamwar.sql.EventRelation; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; import lombok.Getter; @@ -70,12 +72,21 @@ public class FightStatistics { } private void setEventResult() { - if (FightSystem.getLastWinner() == null) + if (FightSystem.getLastWinner() == null) { Config.EventKampf.setErgebnis(0); - else if (FightSystem.getLastWinner().isBlue()) + } else if (FightSystem.getLastWinner().isBlue()) { Config.EventKampf.setErgebnis(1); - else + } else { Config.EventKampf.setErgebnis(2); + } + + Config.EventKampf.getDependents().forEach(EventRelation::apply); + + Config.EventKampf.getGroup().ifPresent(group -> { + if (group.getLastFight().map(EventFight::getFightID).orElse(-1) == Config.EventKampf.getFightID() && !group.needsTieBreak()) { + group.getDependents().forEach(EventRelation::apply); + } + }); } private void disable() { From e3179c69aaea55cad49617baaf62770973d3b98c Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 8 May 2025 17:32:12 +0200 Subject: [PATCH 011/153] Refactor event group management and routing system --- .../SQL/src/de/steamwar/sql/EventFight.java | 6 + .../SQL/src/de/steamwar/sql/EventGroup.java | 49 ++++++-- .../src/de/steamwar/sql/EventRelation.java | 5 + WebsiteBackend/src/de/steamwar/data/Groups.kt | 89 -------------- WebsiteBackend/src/de/steamwar/routes/Data.kt | 4 - .../src/de/steamwar/routes/EventFights.kt | 32 ++--- .../src/de/steamwar/routes/EventGroups.kt | 94 +++++++++++++++ .../src/de/steamwar/routes/EventRelations.kt | 109 +++++++++++++++++ .../src/de/steamwar/routes/EventTeams.kt | 52 ++++++++ .../src/de/steamwar/routes/Events.kt | 114 ++++++++++-------- .../src/de/steamwar/routes/Routes.kt | 1 - 11 files changed, 385 insertions(+), 170 deletions(-) delete mode 100644 WebsiteBackend/src/de/steamwar/data/Groups.kt create mode 100644 WebsiteBackend/src/de/steamwar/routes/EventGroups.kt create mode 100644 WebsiteBackend/src/de/steamwar/routes/EventRelations.kt create mode 100644 WebsiteBackend/src/de/steamwar/routes/EventTeams.kt diff --git a/CommonCore/SQL/src/de/steamwar/sql/EventFight.java b/CommonCore/SQL/src/de/steamwar/sql/EventFight.java index e231fc70d..d23e74117 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/EventFight.java +++ b/CommonCore/SQL/src/de/steamwar/sql/EventFight.java @@ -47,6 +47,7 @@ public class EventFight implements Comparable { private static final Statement create = table.insertFields(true, "eventID", "startTime", "spielmodus", "map", "teamBlue", "teamRed", "spectatePort"); private static final Statement update = table.update(Table.PRIMARY, "startTime", "spielModus", "map", "teamBlue", "teamRed", "spectatePort"); + private static final Statement setGroup = table.update(Table.PRIMARY, "GroupID"); private static final Statement delete = table.delete(Table.PRIMARY); @Getter @@ -152,6 +153,11 @@ public class EventFight implements Comparable { setFight.update(fight, fightID); } + public void setGroup(EventGroup group) { + setGroup.update(group.getId(), fightID); + this.groupId = group.getId(); + } + public boolean hasFinished() { return fight != 0 || ergebnis != 0; } diff --git a/CommonCore/SQL/src/de/steamwar/sql/EventGroup.java b/CommonCore/SQL/src/de/steamwar/sql/EventGroup.java index c5c005800..166e7eb15 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/EventGroup.java +++ b/CommonCore/SQL/src/de/steamwar/sql/EventGroup.java @@ -19,11 +19,7 @@ package de.steamwar.sql; -import de.steamwar.sql.internal.Field; -import de.steamwar.sql.internal.SelectStatement; -import de.steamwar.sql.internal.SqlTypeMapper; -import de.steamwar.sql.internal.Table; -import lombok.AllArgsConstructor; +import de.steamwar.sql.internal.*; import lombok.Getter; import lombok.Setter; @@ -32,7 +28,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; -@AllArgsConstructor @Getter @Setter public class EventGroup { @@ -45,8 +40,17 @@ public class EventGroup { private static final SelectStatement get = table.select(Table.PRIMARY); private static final SelectStatement byEvent = new SelectStatement<>(table, "SELECT * FROM EventGroup WHERE EventID = ?"); + private static final Statement insert = table.insertFields(true, "EventID", "Name", "Type"); + private static final Statement update = table.update(Table.PRIMARY, "Name", "Type", "PointsPerWin", "PointsPerLoss", "PointsPerDraw"); + private static final Statement delete = table.delete(Table.PRIMARY); + public static List get(Event eventID) { - return byEvent.listSelect(eventID); + return byEvent.listSelect(eventID.getEventID()); + } + + public static EventGroup create(Event event, String name, EventGroupType type) { + int key = insert.insertGetKey(event.getEventID(), name, type); + return EventGroup.get(key).get(); } public static Optional get(int id) { @@ -56,7 +60,10 @@ public class EventGroup { @Field(keys = Table.PRIMARY) private final int id; - @Field + @Field(keys = "EVENT_NAME") + private int eventID; + + @Field(keys = "EVENT_NAME") private String name; @Field @@ -71,6 +78,16 @@ public class EventGroup { @Field private int pointsPerDraw; + public EventGroup(int id, int eventID, String name, EventGroupType type, int pointsPerWin, int pointsPerLoss, int pointsPerDraw) { + this.id = id; + this.eventID = eventID; + this.name = name; + this.type = type; + this.pointsPerWin = pointsPerWin; + this.pointsPerLoss = pointsPerLoss; + this.pointsPerDraw = pointsPerDraw; + } + private Map points; public List getFights() { @@ -88,8 +105,9 @@ public class EventGroup { public Map calculatePoints() { if (points == null) { Map teams = new HashMap<>(); + points = new HashMap<>(); - for(EventFight fight : getFights()) { + for (EventFight fight : getFights()) { int blueTeamAdd = 0; int redTeamAdd = 0; @@ -121,10 +139,23 @@ public class EventGroup { return points; } + public void update(String name, EventGroupType type, int pointsPerWin, int pointsPerLoss, int pointsPerDraw) { + update.update(id, name, type, pointsPerWin, pointsPerLoss, pointsPerDraw); + this.name = name; + this.type = type; + this.pointsPerWin = pointsPerWin; + this.pointsPerLoss = pointsPerLoss; + this.pointsPerDraw = pointsPerDraw; + } + public boolean needsTieBreak() { return calculatePoints().values().stream().sorted().limit(2).distinct().count() < 2; } + public void delete() { + delete.update(id); + } + public static enum EventGroupType { GROUP_STAGE, ELIMINATION_STAGE diff --git a/CommonCore/SQL/src/de/steamwar/sql/EventRelation.java b/CommonCore/SQL/src/de/steamwar/sql/EventRelation.java index 13b35f021..28c756eec 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/EventRelation.java +++ b/CommonCore/SQL/src/de/steamwar/sql/EventRelation.java @@ -42,11 +42,16 @@ public class EventRelation { private static final SelectStatement get = new SelectStatement<>(table, "SELECT * FROM EventRelation WHERE FromType = ? AND FromId = ?"); private static final SelectStatement byId = new SelectStatement<>(table, "SELECT * FROM EventRelation WHERE id = ?"); + private static final SelectStatement byEvent = new SelectStatement<>(table, "SELECT ER.* FROM EventRelation ER JOIN EventFight EF ON EF.id = ER.fightId WHERE EF.EventID = ?"); private static final Statement insert = table.insertAll(true); private static final Statement update = table.update(Table.PRIMARY, "fromType", "fromId", "fromPlace"); private static final Statement updateTeam = table.update(Table.PRIMARY, "fightTeam"); private static final Statement delete = table.delete(Table.PRIMARY); + public static List get(Event event) { + return byId.listSelect(event.getEventID()); + } + public static EventRelation get(int id) { return byId.select(id); } diff --git a/WebsiteBackend/src/de/steamwar/data/Groups.kt b/WebsiteBackend/src/de/steamwar/data/Groups.kt deleted file mode 100644 index 2ecff0547..000000000 --- a/WebsiteBackend/src/de/steamwar/data/Groups.kt +++ /dev/null @@ -1,89 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2024 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.data - -import kotlinx.serialization.ExperimentalSerializationApi -import kotlinx.serialization.Serializable -import kotlinx.serialization.cbor.Cbor -import kotlinx.serialization.decodeFromByteArray -import kotlinx.serialization.encodeToByteArray - -@Serializable -data class GroupsData(val groups: MutableList) - -@Serializable -data class GroupData(val name: String, val fights: MutableList) - -@OptIn(ExperimentalSerializationApi::class) -class Groups { - companion object { - private var groups: GroupsData = if (kGroupsFile.exists()) { - Cbor.decodeFromByteArray(kGroupsFile.readBytes()) - } else { - if (!kGroupsFile.parentFile.exists()) { - kGroupsFile.parentFile.mkdirs() - } - kGroupsFile.createNewFile() - kGroupsFile.writeBytes(Cbor.encodeToByteArray(GroupsData(mutableListOf()))) - - GroupsData(mutableListOf()) - } - - fun getGroup(name: String): GroupData? { - return groups.groups.find { it.name == name } - } - - fun getGroup(fight: Int): GroupData? { - return groups.groups.find { it.fights.contains(fight) } - } - - fun getOrCreateGroup(name: String): GroupData { - val group = getGroup(name) - if (group != null) { - return group - } - val newGroup = GroupData(name, mutableListOf()) - groups.groups.add(newGroup) - return newGroup - } - - fun resetGroup(fight: Int, save: Boolean = false) { - val oldGroup = getGroup(fight) - oldGroup?.fights?.remove(fight) - if(oldGroup?.fights?.isEmpty() == true) { - groups.groups.remove(oldGroup) - } - if(save) { - kGroupsFile.writeBytes(Cbor.encodeToByteArray(groups)) - } - } - - fun setGroup(fight: Int, group: String) { - resetGroup(fight) - val newGroup = getOrCreateGroup(group) - newGroup.fights.add(fight) - kGroupsFile.writeBytes(Cbor.encodeToByteArray(groups)) - } - - fun getAllGroups(): List { - return groups.groups.map { it.name } - } - } -} \ No newline at end of file diff --git a/WebsiteBackend/src/de/steamwar/routes/Data.kt b/WebsiteBackend/src/de/steamwar/routes/Data.kt index 0a2dd3ae1..6af82bfe1 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Data.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Data.kt @@ -20,7 +20,6 @@ package de.steamwar.routes import de.steamwar.ResponseError -import de.steamwar.data.Groups import de.steamwar.data.getCachedSkin import de.steamwar.plugins.SWAuthPrincipal import de.steamwar.plugins.SWPermissionCheck @@ -102,9 +101,6 @@ fun Route.configureDataRoutes() { } call.respond(YamlConfiguration.loadConfiguration(file).getStringList("Server.Maps")) } - get("/groups") { - call.respond(Groups.getAllGroups()) - } } get("/server") { try { diff --git a/WebsiteBackend/src/de/steamwar/routes/EventFights.kt b/WebsiteBackend/src/de/steamwar/routes/EventFights.kt index e95ea89da..1f0e63c5a 100644 --- a/WebsiteBackend/src/de/steamwar/routes/EventFights.kt +++ b/WebsiteBackend/src/de/steamwar/routes/EventFights.kt @@ -20,12 +20,7 @@ package de.steamwar.routes import de.steamwar.ResponseError -import de.steamwar.data.Groups -import de.steamwar.plugins.SWPermissionCheck -import de.steamwar.sql.EventFight -import de.steamwar.sql.SteamwarUser -import de.steamwar.sql.Team -import de.steamwar.sql.UserPerm +import de.steamwar.sql.* import io.ktor.http.* import io.ktor.server.application.* import io.ktor.server.request.* @@ -45,7 +40,7 @@ data class ResponseEventFight( val start: Long, val ergebnis: Int, val spectatePort: Int?, - val group: String? + val group: ResponseGroups? ) { constructor(eventFight: EventFight) : this( eventFight.fightID, @@ -56,7 +51,7 @@ data class ResponseEventFight( eventFight.startTime.time, eventFight.ergebnis, eventFight.spectatePort, - Groups.getGroup(eventFight.fightID)?.name + eventFight.group.orElse(null)?.let { ResponseGroups(it) } ) } @@ -72,7 +67,7 @@ data class UpdateEventFight( val start: Long? = null, val spielmodus: String? = null, val map: String? = null, - val group: String? = null, + val group: Int? = null, val spectatePort: Int? = null ) @@ -85,14 +80,14 @@ data class CreateEventFight( val redTeam: Int, val start: Long, val spectatePort: Int? = null, - val group: String? = null + val group: Int? = null ) fun Route.configureEventFightRoutes() { route("/fights") { - install(SWPermissionCheck) { - allowMethod(HttpMethod.Get) - permission = UserPerm.MODERATION + get { + val event = call.receiveEvent() ?: return@get + call.respond(EventFight.getEvent(event.eventID).map { ResponseEventFight(it) }) } post { val fight = call.receiveNullable() @@ -100,6 +95,7 @@ fun Route.configureEventFightRoutes() { call.respond(HttpStatusCode.BadRequest, ResponseError("Invalid body")) return@post } + val eventFight = EventFight.create( fight.event, Timestamp.from(Instant.ofEpochMilli(fight.start)), @@ -110,9 +106,7 @@ fun Route.configureEventFightRoutes() { fight.spectatePort ) if (fight.group != null) { - if (fight.group != "null") { - Groups.setGroup(eventFight.fightID, fight.group) - } + eventFight.groupId = fight.group } call.respond(HttpStatusCode.Created, ResponseEventFight(eventFight)) } @@ -133,10 +127,10 @@ fun Route.configureEventFightRoutes() { val spectatePort = updateFight.spectatePort ?: fight.spectatePort if (updateFight.group != null) { - if (updateFight.group == "null") { - Groups.resetGroup(fight.fightID, true) + if (updateFight.group == -1) { + fight.groupId = null } else { - Groups.setGroup(fight.fightID, updateFight.group) + fight.groupId = updateFight.group } } fight.update(start, spielmodus, map, teamBlue, teamRed, spectatePort) diff --git a/WebsiteBackend/src/de/steamwar/routes/EventGroups.kt b/WebsiteBackend/src/de/steamwar/routes/EventGroups.kt new file mode 100644 index 000000000..38260e74b --- /dev/null +++ b/WebsiteBackend/src/de/steamwar/routes/EventGroups.kt @@ -0,0 +1,94 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 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.routes + +import de.steamwar.sql.EventGroup +import de.steamwar.sql.EventGroup.EventGroupType +import io.ktor.http.* +import io.ktor.server.application.* +import io.ktor.server.request.* +import io.ktor.server.response.* +import io.ktor.server.routing.* +import kotlinx.serialization.Serializable + +@Serializable +data class CreateEventGroup(val name: String, val type: EventGroupType) + +@Serializable +data class UpdateEventGroup( + val name: String? = null, + val type: EventGroupType? = null, + val pointsPerWin: Int? = null, + val pointsPerLoss: Int? = null, + val pointsPerDraw: Int? = null, +) + +fun Route.configureEventGroups() { + route("/groups") { + get { + val event = call.receiveEvent() ?: return@get + call.respond(EventGroup.get(event).map { ResponseGroups(it) }) + } + post { + val event = call.receiveEvent() ?: return@post + val createEventGroup = call.receive() + val group = EventGroup.create(event, createEventGroup.name, createEventGroup.type) + call.respond(ResponseGroups(group)) + } + route("/{group}") { + get { + val group = call.receiveEventGroup() ?: return@get + call.respond(ResponseGroups(group)) + } + put { + val group = call.receiveEventGroup() ?: return@put + val updateEventGroup = call.receive() + val name = updateEventGroup.name ?: group.name + val type = updateEventGroup.type ?: group.type + val pointsPerWin = updateEventGroup.pointsPerWin ?: group.pointsPerWin + val pointsPerLoss = updateEventGroup.pointsPerLoss ?: group.pointsPerLoss + val pointsPerDraw = updateEventGroup.pointsPerDraw ?: group.pointsPerDraw + group.update(name, type, pointsPerWin, pointsPerLoss, pointsPerDraw) + call.respond(ResponseGroups(EventGroup.get(group.id).orElse(null) ?: return@put)) + } + delete { + val group = call.receiveEventGroup() ?: return@delete + group.delete() + call.respond(HttpStatusCode.NoContent) + } + } + } +} + +suspend fun ApplicationCall.receiveEventGroup(): EventGroup? { + val groupId = parameters["group"]?.toIntOrNull() + if (groupId == null) { + respond(HttpStatusCode.BadRequest) + return null + } + + val group = EventGroup.get(groupId).orElse(null) + if (group == null) { + respond(HttpStatusCode.NotFound) + return null + } + + return group +} \ No newline at end of file diff --git a/WebsiteBackend/src/de/steamwar/routes/EventRelations.kt b/WebsiteBackend/src/de/steamwar/routes/EventRelations.kt new file mode 100644 index 000000000..c8af58666 --- /dev/null +++ b/WebsiteBackend/src/de/steamwar/routes/EventRelations.kt @@ -0,0 +1,109 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 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.routes + +import de.steamwar.sql.EventFight +import de.steamwar.sql.EventGroup +import de.steamwar.sql.EventRelation +import io.ktor.http.* +import io.ktor.server.application.* +import io.ktor.server.request.* +import io.ktor.server.response.* +import io.ktor.server.routing.* +import kotlinx.serialization.Serializable + +@Serializable +data class CreateEventRelation(val fightId: Int, val team: EventRelation.FightTeam, val fromType: EventRelation.FromType, val fromId: Int, val fromPlace: Int) + +@Serializable +data class UpdateEventRelation(val team: EventRelation.FightTeam? = null, val from: UpdateFromRelation? = null) + +@Serializable +data class UpdateFromRelation(val fromType: EventRelation.FromType, val fromId: Int, val fromPlace: Int) + +fun Route.configureEventRelations() { + route("/relations") { + get { + val event = call.receiveEvent() ?: return@get + + call.respond(EventRelation.get(event).map { ResponseRelation(it) }) + } + post { + val create = call.receive() + + val fight = EventFight.get(create.fightId) ?: return@post call.respond(HttpStatusCode.NotFound) + + when (create.fromType) { + EventRelation.FromType.FIGHT -> EventFight.get(create.fromId) ?: return@post call.respond(HttpStatusCode.BadRequest) + EventRelation.FromType.GROUP -> EventGroup.get(create.fromId) ?: return@post call.respond(HttpStatusCode.BadRequest) + } + + val relation = EventRelation.create(fight, create.team, create.fromType, create.fromId, create.fromPlace) + + call.respond(ResponseRelation(relation)) + } + route("/{relation}") { + get { + val relation = call.receiveEventRelation() ?: return@get + call.respond(ResponseRelation(relation)) + } + put { + val relation = call.receiveEventRelation() ?: return@put + val update = call.receive() + + update.from?.let { + when(it.fromType) { + EventRelation.FromType.FIGHT -> relation.setFromFight(EventFight.get(it.fromId) ?: return@put call.respond(HttpStatusCode.BadRequest), + it.fromPlace + ) + EventRelation.FromType.GROUP -> relation.setFromGroup(EventGroup.get(it.fromId).orElse(null) ?: return@put call.respond(HttpStatusCode.BadRequest), + it.fromPlace + ) + } + } + + update.team?.let { relation.setUpdateTeam(it) } + + call.respond(ResponseRelation(EventRelation.get(relation.id))) + } + delete { + val relation = call.receiveEventRelation() ?: return@delete + relation.delete() + call.respond(HttpStatusCode.NoContent) + } + } + } +} + +suspend fun ApplicationCall.receiveEventRelation(): EventRelation? { + val relationId = parameters["relation"]?.toIntOrNull() + if (relationId == null) { + respond(HttpStatusCode.BadRequest) + return null + } + + val relation = EventRelation.get(relationId) + if (relation == null) { + respond(HttpStatusCode.NotFound) + return null + } + + return relation +} \ No newline at end of file diff --git a/WebsiteBackend/src/de/steamwar/routes/EventTeams.kt b/WebsiteBackend/src/de/steamwar/routes/EventTeams.kt new file mode 100644 index 000000000..caacc0a98 --- /dev/null +++ b/WebsiteBackend/src/de/steamwar/routes/EventTeams.kt @@ -0,0 +1,52 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 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.routes + +import de.steamwar.sql.TeamTeilnahme +import io.ktor.http.* +import io.ktor.server.application.* +import io.ktor.server.request.* +import io.ktor.server.response.* +import io.ktor.server.routing.* + +fun Route.configureEventTeams() { + route("/teams") { + get { + val event = call.receiveEvent() ?: return@get + call.respond(TeamTeilnahme.getTeams(event.eventID).map { ResponseTeam(it) }) + } + put { + val event = call.receiveEvent() ?: return@put + val team = call.receive>() + team.forEach { + TeamTeilnahme.teilnehmen(it, event.eventID) + } + call.respond(HttpStatusCode.NoContent) + } + delete { + val event = call.receiveEvent() ?: return@delete + val team = call.receive>() + team.forEach { + TeamTeilnahme.notTeilnehmen(it, event.eventID) + } + call.respond(HttpStatusCode.NoContent) + } + } +} \ No newline at end of file diff --git a/WebsiteBackend/src/de/steamwar/routes/Events.kt b/WebsiteBackend/src/de/steamwar/routes/Events.kt index d40cdd3bf..1ef7ba835 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Events.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Events.kt @@ -20,9 +20,10 @@ package de.steamwar.routes import de.steamwar.ResponseError -import de.steamwar.data.Groups import de.steamwar.plugins.SWPermissionCheck import de.steamwar.sql.* +import de.steamwar.sql.EventGroup.EventGroupType +import de.steamwar.sql.EventRelation.FromType import io.ktor.http.* import io.ktor.server.application.* import io.ktor.server.request.* @@ -39,6 +40,45 @@ data class ShortEvent(val id: Int, val name: String, val start: Long, val end: L constructor(event: Event) : this(event.eventID, event.eventName, event.start.time, event.end.time) } +@Serializable +data class ResponseGroups( + val id: Int, + val name: String, + val pointsPerWin: Int, + val pointsPerLoss: Int, + val pointsPerDraw: Int, + val type: EventGroupType, + val points: Map +) { + constructor(group: EventGroup, short: Boolean = false) : this( + group.id, + group.name, + group.pointsPerWin, + group.pointsPerLoss, + group.pointsPerDraw, + group.type, + if (short) mapOf() else group.calculatePoints().mapKeys { it.key.teamId }) +} + +@Serializable +data class ResponseRelation( + val id: Int, + val fight: ResponseEventFight, + val type: FromType, + val fromFight: ResponseEventFight? = null, + val fromGroup: ResponseGroups? = null, + val fromPlace: Int +) { + constructor(relation: EventRelation) : this( + relation.id, + ResponseEventFight(relation.fight), + relation.fromType, + relation.fromFight.map { ResponseEventFight(it) }.orElse(null), + relation.fromGroup.map { ResponseGroups(it) }.orElse(null), + relation.fromPlace + ) +} + @Serializable data class ResponseEvent( val id: Int, @@ -49,7 +89,6 @@ data class ResponseEvent( val maxTeamMembers: Int, val schemType: String?, val publicSchemsOnly: Boolean, - val referees: List, ) { constructor(event: Event) : this( event.eventID, @@ -60,7 +99,6 @@ data class ResponseEvent( event.maximumTeamMembers, event.schematicType?.toDB(), event.publicSchemsOnly(), - Referee.get(event.eventID).map { ResponseUser(SteamwarUser.get(it)) } ) } @@ -68,8 +106,20 @@ data class ResponseEvent( data class ExtendedResponseEvent( val event: ResponseEvent, val teams: List, - val fights: List -) + val groups: List, + val fights: List, + val referees: List, + val relations: List +) { + constructor(event: Event) : this( + ResponseEvent(event), + TeamTeilnahme.getTeams(event.eventID).map { ResponseTeam(it) }, + EventGroup.get(event).map { ResponseGroups(it) }, + EventFight.getEvent(event.eventID).map { ResponseEventFight(it) }, + Referee.get(event.eventID).map { ResponseUser(SteamwarUser.get(it)) }, + EventRelation.get(event).map { ResponseRelation(it) } + ) +} @Serializable data class CreateEvent(val name: String, val start: Long, val end: Long) @@ -111,49 +161,11 @@ fun Route.configureEventsRoute() { } route("/{id}") { get { - val id = call.parameters["id"]?.toIntOrNull() - if (id == null) { - call.respond(HttpStatusCode.BadRequest, ResponseError("Invalid ID")) - return@get - } - val event = Event.get(id) - if (event == null) { - call.respond(HttpStatusCode.NotFound, ResponseError("Event not found")) - return@get - } + val event = call.receiveEvent() ?: return@get call.respond( - ExtendedResponseEvent( - ResponseEvent(event), - TeamTeilnahme.getTeams(event.eventID).map { ResponseTeam(it) }, - EventFight.getEvent(event.eventID).map { ResponseEventFight(it) }) + ExtendedResponseEvent(event) ) } - get("/teams") { - val id = call.parameters["id"]?.toIntOrNull() - if (id == null) { - call.respond(HttpStatusCode.BadRequest, ResponseError("Invalid ID")) - return@get - } - val event = Event.get(id) - if (event == null) { - call.respond(HttpStatusCode.NotFound, ResponseError("Event not found")) - return@get - } - call.respond(TeamTeilnahme.getTeams(event.eventID).map { ResponseTeam(it) }) - } - get("/fights") { - val id = call.parameters["id"]?.toIntOrNull() - if (id == null) { - call.respond(HttpStatusCode.BadRequest, ResponseError("Invalid ID")) - return@get - } - val event = Event.get(id) - if (event == null) { - call.respond(HttpStatusCode.NotFound, ResponseError("Event not found")) - return@get - } - call.respond(EventFight.getEvent(event.eventID).map { ResponseEventFight(it) }) - } get("/csv") { val event = call.receiveEvent() ?: return@get @@ -164,7 +176,7 @@ fun Route.configureEventsRoute() { csv.appendLine() val blue = Team.get(it.teamBlue) val red = Team.get(it.teamRed) - val winner = when(it.ergebnis) { + val winner = when (it.ergebnis) { 1 -> blue.teamName 2 -> red.teamName 3 -> "Tie" @@ -176,7 +188,7 @@ fun Route.configureEventsRoute() { Team.get(it.teamBlue).teamName, Team.get(it.teamRed).teamName, winner, - Groups.getGroup(it.fightID)?.name ?: "Ungrouped" + it.group.map { it.name }.orElse("Ungrouped") ).joinToString(",") ) } @@ -200,7 +212,9 @@ fun Route.configureEventsRoute() { val end = updateEvent.end?.let { Timestamp.from(Instant.ofEpochMilli(it)) } ?: event.end val maxTeamMembers = updateEvent.maxTeamMembers ?: event.maximumTeamMembers - val schemType = if (updateEvent.schemType == "null") null else updateEvent.schemType?.let { SchematicType.fromDB(it) } ?: event.schematicType + val schemType = + if (updateEvent.schemType == "null") null else updateEvent.schemType?.let { SchematicType.fromDB(it) } + ?: event.schematicType val publicSchemsOnly = updateEvent.publicSchemsOnly ?: event.publicSchemsOnly() if (updateEvent.addReferee != null) { @@ -231,6 +245,10 @@ fun Route.configureEventsRoute() { event.delete() call.respond(HttpStatusCode.NoContent) } + configureEventFightRoutes() + configureEventTeams() + configureEventGroups() + configureEventRelations() } } } diff --git a/WebsiteBackend/src/de/steamwar/routes/Routes.kt b/WebsiteBackend/src/de/steamwar/routes/Routes.kt index 388f80556..f4e883eec 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Routes.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Routes.kt @@ -28,7 +28,6 @@ fun Application.configureRoutes() { authenticate("sw-auth", optional = true) { configureEventsRoute() configureDataRoutes() - configureEventFightRoutes() configureUserPerms() configureStats() configurePage() From 6e9db276efb94c5eca3e7473af85da777ea6a693 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 10 May 2025 22:22:43 +0200 Subject: [PATCH 012/153] Add event referees management and teams endpoint. Introduced a new route for managing event referees with get, put, and delete operations. Also added an endpoint to fetch all teams, and integrated the referees routing into event configuration. --- WebsiteBackend/src/de/steamwar/routes/Data.kt | 4 ++ .../src/de/steamwar/routes/EventReferees.kt | 54 +++++++++++++++++++ .../src/de/steamwar/routes/Events.kt | 1 + 3 files changed, 59 insertions(+) create mode 100644 WebsiteBackend/src/de/steamwar/routes/EventReferees.kt diff --git a/WebsiteBackend/src/de/steamwar/routes/Data.kt b/WebsiteBackend/src/de/steamwar/routes/Data.kt index 6af82bfe1..a76720637 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Data.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Data.kt @@ -25,6 +25,7 @@ import de.steamwar.plugins.SWAuthPrincipal import de.steamwar.plugins.SWPermissionCheck import de.steamwar.sql.SchematicType import de.steamwar.sql.SteamwarUser +import de.steamwar.sql.Team import de.steamwar.sql.UserPerm import de.steamwar.sql.loadSchematicTypes import de.steamwar.util.fetchData @@ -77,6 +78,9 @@ fun Route.configureDataRoutes() { get("/users") { call.respond(SteamwarUser.getAll().map { ResponseUser(it) }) } + get("/teams") { + call.respond(Team.getAll().map { ResponseTeam(it) }) + } get("/schematicTypes") { val types = mutableListOf() loadSchematicTypes(types, mutableMapOf()) diff --git a/WebsiteBackend/src/de/steamwar/routes/EventReferees.kt b/WebsiteBackend/src/de/steamwar/routes/EventReferees.kt new file mode 100644 index 000000000..051c31cdc --- /dev/null +++ b/WebsiteBackend/src/de/steamwar/routes/EventReferees.kt @@ -0,0 +1,54 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 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.routes + +import de.steamwar.sql.Referee +import de.steamwar.sql.SteamwarUser +import io.ktor.http.* +import io.ktor.server.application.* +import io.ktor.server.request.* +import io.ktor.server.response.* +import io.ktor.server.routing.* +import java.util.* + +fun Route.configureEventRefereesRouting() { + route("/referees") { + get { + val event = call.receiveEvent() ?: return@get + call.respond(Referee.get(event.eventID).map { ResponseUser(SteamwarUser.get(it)) }) + } + put { + val event = call.receiveEvent() ?: return@put + val referees = call.receive>() + referees.forEach { + Referee.add(event.eventID, SteamwarUser.get(UUID.fromString(it)).id) + } + call.respond(Referee.get(event.eventID).map { ResponseUser(SteamwarUser.get(it)) }) + } + delete { + val event = call.receiveEvent() ?: return@delete + val referees = call.receive>() + referees.forEach { + Referee.remove(event.eventID, SteamwarUser.get(UUID.fromString(it)).id) + } + call.respond(Referee.get(event.eventID).map { ResponseUser(SteamwarUser.get(it)) }) + } + } +} \ No newline at end of file diff --git a/WebsiteBackend/src/de/steamwar/routes/Events.kt b/WebsiteBackend/src/de/steamwar/routes/Events.kt index 1ef7ba835..8dbb3993d 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Events.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Events.kt @@ -249,6 +249,7 @@ fun Route.configureEventsRoute() { configureEventTeams() configureEventGroups() configureEventRelations() + configureEventRefereesRouting() } } } From 79edc1c59184ea038eee43a6a8001b39acdeba19 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Mon, 21 Apr 2025 00:02:13 +0200 Subject: [PATCH 013/153] Add Simulator to improvements --- .../simulator/gui/SimulatorGroupGui.java | 8 ++--- .../gui/SimulatorGroupSettingsGui.java | 34 +++++++++--------- .../features/simulator/gui/SimulatorGui.java | 2 +- .../simulator/gui/SimulatorMaterialGui.java | 2 +- .../simulator/gui/SimulatorObserverGui.java | 22 ++++++------ .../SimulatorObserverPhaseSettingsGui.java | 20 +++++------ .../gui/SimulatorObserverSettingsGui.java | 34 +++++++++--------- .../simulator/gui/SimulatorRedstoneGui.java | 22 ++++++------ .../SimulatorRedstonePhaseSettingsGui.java | 28 +++++++-------- .../gui/SimulatorRedstoneSettingsGui.java | 34 +++++++++--------- .../simulator/gui/SimulatorSettingsGui.java | 26 +++++++------- .../simulator/gui/SimulatorTNTGui.java | 26 +++++++------- .../gui/SimulatorTNTPhaseSettingsGui.java | 36 +++++++++---------- .../gui/SimulatorTNTSettingsGui.java | 34 +++++++++--------- .../simulator/gui/base/SimulatorPageGui.java | 8 ++--- .../gui/base/SimulatorScrollGui.java | 8 ++--- .../src/de/steamwar/inventory/SWItem.java | 32 ++++++++++++----- 17 files changed, 195 insertions(+), 181 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java index c3b8ee1a9..185a22cac 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java @@ -70,12 +70,12 @@ public class SimulatorGroupGui extends SimulatorPageGui> { inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); - })); + }).setCustomModelData(1)); inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { simulatorGroup.getElements().clear(); SimulatorWatcher.update(simulator); - })); + }).setCustomModelData(1)); inventory.setItem(4, simulatorGroup.toItem(player, clickType -> { if (simulatorGroup.getMaterial() == null) return; @@ -85,7 +85,7 @@ public class SimulatorGroupGui extends SimulatorPageGui> { inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> { new SimulatorGroupSettingsGui(player, simulator, simulatorGroup, this).open(); - })); + }).setCustomModelData(1)); boolean disabled = simulatorGroup.getMaterial() == null ? simulatorGroup.getElements().stream().allMatch(SimulatorElement::isDisabled) : simulatorGroup.isDisabled(); inventory.setItem(50, new SWItem(disabled ? Material.ENDER_PEARL : Material.ENDER_EYE, simulatorGroup.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { if (simulatorGroup.getMaterial() == null) { @@ -96,7 +96,7 @@ public class SimulatorGroupGui extends SimulatorPageGui> { simulatorGroup.setDisabled(!disabled); } SimulatorWatcher.update(simulator); - })); + }).setCustomModelData(1)); } @Override diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java index ba5b984ee..e7617297b 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java @@ -58,7 +58,7 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); - })); + }).setCustomModelData(1)); // Material Chooser inventory.setItem(4, simulatorGroup.toItem(player, clickType -> { @@ -69,10 +69,10 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { // Base Tick int baseTicks = simulatorGroup.getBaseTick(); - inventory.setItem(9, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { simulatorGroup.changeBaseTicks(clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> { new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> { if (integer < 0) return false; @@ -83,14 +83,14 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { }); baseTick.getItemStack().setAmount(Math.max(1, Math.min(baseTicks, 64))); inventory.setItem(18, baseTick); - inventory.setItem(27, SWItem.getDye(baseTicks > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(27, new SWItem(SWItem.getDye(baseTicks > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { if (baseTicks - (clickType.isShiftClick() ? 5 : 1) < 0) { simulatorGroup.changeBaseTicks(-baseTicks); } else { simulatorGroup.changeBaseTicks(clickType.isShiftClick() ? -5 : -1); } SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); boolean allTNT = simulatorGroup.getElements().stream().allMatch(TNTElement.class::isInstance); @@ -163,10 +163,10 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { } //Pos X - inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> { simulatorGroup.move(clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1, 0, 0); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); inventory.setItem(24, new SWItem(Material.PAPER, "§eX", clickType -> { new SimulatorAnvilGui<>(player, "Relative X", "", Double::parseDouble, number -> { if(!allTNT){ @@ -177,16 +177,16 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { return true; }, this).setItem(Material.PAPER).open(); })); - inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { simulatorGroup.move(clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0, 0); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); //Pos Y - inventory.setItem(16, SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> { simulatorGroup.move(0, clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1, 0); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); inventory.setItem(25, new SWItem(Material.PAPER, "§eY", clickType -> { new SimulatorAnvilGui<>(player, "Relative Y", "", Double::parseDouble, number -> { if(!allTNT){ @@ -197,16 +197,16 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { return true; }, this).setItem(Material.PAPER).open(); })); - inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { simulatorGroup.move(0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); //Pos Z - inventory.setItem(17, SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> { simulatorGroup.move(0, 0, clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); inventory.setItem(26, new SWItem(Material.PAPER, "§eZ", clickType -> { new SimulatorAnvilGui<>(player, "Relative Z", "", Double::parseDouble, number -> { if(!allTNT){ @@ -217,9 +217,9 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { return true; }, this).setItem(Material.PAPER).open(); })); - inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { simulatorGroup.move(0, 0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGui.java index e35f0eaa5..e165b851d 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGui.java @@ -50,7 +50,7 @@ public class SimulatorGui extends SimulatorPageGui { })); inventory.setItem(49, new SWItem(Material.REPEATER, "§eSettings", clickType -> { new SimulatorSettingsGui(player, simulator, this).open(); - })); + }).setCustomModelData(1)); } @Override diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorMaterialGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorMaterialGui.java index f081374d8..8d57b830c 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorMaterialGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorMaterialGui.java @@ -75,7 +75,7 @@ public class SimulatorMaterialGui extends SimulatorPageGui { })); inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); - })); + }).setCustomModelData(1)); } @Override diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverGui.java index 426693874..dedcc69ea 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverGui.java @@ -82,12 +82,12 @@ public class SimulatorObserverGui extends SimulatorScrollGui { new SimulatorGroupGui(player, simulator, newParent, simulatorGui).open(); } } - })); + }).setCustomModelData(1)); inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { observer.getPhases().clear(); SimulatorWatcher.update(simulator); - })); + }).setCustomModelData(1)); // Material Chooser inventory.setItem(4, observer.toItem(player, clickType -> { @@ -97,18 +97,18 @@ public class SimulatorObserverGui extends SimulatorScrollGui { // Settings inventory.setItem(47, new SWItem(Material.REPEATER, "§eSettings", clickType -> { new SimulatorObserverSettingsGui(player, simulator, observer, this).open(); - })); + }).setCustomModelData(1)); // Enable/Disable inventory.setItem(48, new SWItem(observer.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, observer.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { observer.setDisabled(!observer.isDisabled()); SimulatorWatcher.update(simulator); - })); + }).setCustomModelData(1)); // Group chooser inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> { new SimulatorGroupChooserGui(player, simulator, observer, observer.getGroup(simulator), this).open(); - })); + }).setCustomModelData(1)); } @Override @@ -151,15 +151,15 @@ public class SimulatorObserverGui extends SimulatorScrollGui { new SWItem(SWItem.getDye(getter.get() < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { setter.accept(Math.min(max, getter.get() + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }), + }).setCustomModelData(3), observer, new SWItem(SWItem.getDye(getter.get() > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> { setter.accept(Math.max(min, getter.get() - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }), + }).setCustomModelData(3), new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> { new SimulatorObserverPhaseSettingsGui(player, simulator, this.observer, observerPhase, this).open(); - }), + }).setCustomModelData(1), }; } @@ -168,12 +168,12 @@ public class SimulatorObserverGui extends SimulatorScrollGui { return new SWItem[]{ new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { addNewPhase(clickType.isShiftClick()); - }), + }).setCustomModelData(3), new SWItem(Material.QUARTZ, "§eObserver§8:§a New Phase", clickType -> { addNewPhase(false); - }), + }).setCustomModelData(1), new SWItem(SWItem.getDye(8), "§7", clickType -> { - }), + }).setCustomModelData(3), }; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverPhaseSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverPhaseSettingsGui.java index f7925c343..0653ef987 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverPhaseSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverPhaseSettingsGui.java @@ -62,7 +62,7 @@ public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui { // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); - })); + }).setCustomModelData(1)); // Material Chooser inventory.setItem(4, observerElement.toItem(player, clickType -> { @@ -74,7 +74,7 @@ public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui { observerElement.getPhases().remove(observer); back.open(); SimulatorWatcher.update(simulator); - })); + }).setCustomModelData(1)); int index = observerElement.getPhases().indexOf(observer); int min; @@ -95,10 +95,10 @@ public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui { //Tick Offset int offset = observer.getTickOffset(); - inventory.setItem(10, SWItem.getDye(offset < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(10, new SWItem(SWItem.getDye(offset < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { observer.setTickOffset(Math.min(max, offset + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> { new SimulatorAnvilGui<>(player, "Start at", offset + "", Integer::parseInt, integer -> { @@ -111,17 +111,17 @@ public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui { offsetItem.getItemStack().setAmount(Math.max(1, Math.min(offset, 64))); inventory.setItem(19, offsetItem); - inventory.setItem(28, SWItem.getDye(offset > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(28, new SWItem(SWItem.getDye(offset > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { observer.setTickOffset(Math.max(min, offset - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); //Order int order = observer.getOrder(); - inventory.setItem(13, SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(13, new SWItem(SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { observer.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR"); SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eActivation Order§8:§7 " + order, clickType -> { @@ -136,10 +136,10 @@ public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui { orderItem.getItemStack().setAmount(Math.max(1, Math.min(Math.abs(order), 30))); inventory.setItem(22, orderItem); - inventory.setItem(31, SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(31, new SWItem(SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { observer.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); // Update orientation inventory.setItem(25, new SWItem(Material.SUNFLOWER, "§7", clickType -> { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverSettingsGui.java index 8084c7b1c..302245b3e 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverSettingsGui.java @@ -56,7 +56,7 @@ public class SimulatorObserverSettingsGui extends SimulatorBaseGui { // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); - })); + }).setCustomModelData(1)); // Material Chooser inventory.setItem(4, observer.toItem(player, clickType -> { @@ -65,10 +65,10 @@ public class SimulatorObserverSettingsGui extends SimulatorBaseGui { // Base Tick int baseTicks = observer.getBaseTick(); - inventory.setItem(9, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { observer.changeBaseTicks(clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> { new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> { if (integer < 0) return false; @@ -79,20 +79,20 @@ public class SimulatorObserverSettingsGui extends SimulatorBaseGui { }); baseTick.getItemStack().setAmount(Math.max(1, Math.min(baseTicks, 64))); inventory.setItem(18, baseTick); - inventory.setItem(27, SWItem.getDye(baseTicks > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(27, new SWItem(SWItem.getDye(baseTicks > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { if (baseTicks - (clickType.isShiftClick() ? 5 : 1) < 0) { observer.changeBaseTicks(-baseTicks); } else { observer.changeBaseTicks(clickType.isShiftClick() ? -5 : -1); } SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); //Pos X - inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { observer.move(clickType.isShiftClick() ? 5 : 1, 0, 0); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + observer.getPosition().getBlockX(), clickType -> { new SimulatorAnvilGui<>(player, "X", observer.getPosition().getBlockX() + "", Integer::parseInt, i -> { observer.getPosition().setX(i); @@ -100,16 +100,16 @@ public class SimulatorObserverSettingsGui extends SimulatorBaseGui { return true; }, this).open(); })); - inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { observer.move(clickType.isShiftClick() ? -5 : -1, 0, 0); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); //Pos Y - inventory.setItem(16, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { observer.move(0, clickType.isShiftClick() ? 5 : 1, 0); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + observer.getPosition().getBlockY(), clickType -> { new SimulatorAnvilGui<>(player, "Y", observer.getPosition().getBlockY() + "", Integer::parseInt, i -> { observer.getPosition().setY(i); @@ -117,16 +117,16 @@ public class SimulatorObserverSettingsGui extends SimulatorBaseGui { return true; }, this).open(); })); - inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { observer.move(0, clickType.isShiftClick() ? -5 : -1, 0); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); //Pos Z - inventory.setItem(17, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { observer.move(0, 0, clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + observer.getPosition().getBlockZ(), clickType -> { new SimulatorAnvilGui<>(player, "Z", observer.getPosition().getBlockZ() + "", Integer::parseInt, i -> { observer.getPosition().setZ(i); @@ -134,9 +134,9 @@ public class SimulatorObserverSettingsGui extends SimulatorBaseGui { return true; }, this).open(); })); - inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { observer.move(0, 0, clickType.isShiftClick() ? -5 : -1); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java index 2e288895c..9764621a8 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java @@ -88,12 +88,12 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { redstone.getPhases().clear(); SimulatorWatcher.update(simulator); - })); + }).setCustomModelData(1)); // Material Chooser inventory.setItem(4, redstone.toItem(player, clickType -> { @@ -103,18 +103,18 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { new SimulatorRedstoneSettingsGui(player, simulator, redstone, this).open(); - })); + }).setCustomModelData(1)); // Enable/Disable inventory.setItem(48, new SWItem(redstone.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, redstone.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { redstone.setDisabled(!redstone.isDisabled()); SimulatorWatcher.update(simulator); - })); + }).setCustomModelData(1)); // Group chooser inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> { new SimulatorGroupChooserGui(player, simulator, redstone, redstone.getGroup(simulator), this).open(); - })); + }).setCustomModelData(1)); } @Override @@ -166,15 +166,15 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { setter.accept(Math.min(max, getter.get() + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }), + }).setCustomModelData(3), redstone, new SWItem(SWItem.getDye(getter.get() > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> { setter.accept(Math.max(min, getter.get() - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }), + }).setCustomModelData(3), new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> { new SimulatorRedstonePhaseSettingsGui(player, simulator, this.redstone, redstoneSubPhase.phase, this).open(); - }), + }).setCustomModelData(1), }; } @@ -183,12 +183,12 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { addNewPhase(clickType.isShiftClick()); - }), + }).setCustomModelData(3), new SWItem(Material.REDSTONE, "§eRedstone§8:§a New Phase", clickType -> { addNewPhase(false); - }), + }).setCustomModelData(1), new SWItem(SWItem.getDye(8), "§7", clickType -> { - }), + }).setCustomModelData(3), }; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java index 27901b095..29ae1525b 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java @@ -60,7 +60,7 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); - })); + }).setCustomModelData(1)); // Material Chooser inventory.setItem(4, redstoneElement.toItem(player, clickType -> { @@ -72,7 +72,7 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { redstoneElement.getPhases().remove(redstone); back.open(); SimulatorWatcher.update(simulator); - })); + }).setCustomModelData(1)); int index = redstoneElement.getPhases().indexOf(redstone); int min; @@ -96,10 +96,10 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { //Tick Offset int offset = redstone.getTickOffset(); - inventory.setItem(10, SWItem.getDye(offset < maxOffset ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(10, new SWItem(SWItem.getDye(offset < maxOffset ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.setTickOffset(Math.min(maxOffset, offset + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> { new SimulatorAnvilGui<>(player, "Start at", offset + "", Integer::parseInt, integer -> { @@ -112,17 +112,17 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { offsetItem.getItemStack().setAmount(Math.max(1, Math.min(offset, 64))); inventory.setItem(19, offsetItem); - inventory.setItem(28, SWItem.getDye(offset > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(28, new SWItem(SWItem.getDye(offset > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.setTickOffset(Math.max(min, offset - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); //Lifetime int lifetime = redstone.getLifetime(); - inventory.setItem(11, SWItem.getDye(lifetime < maxLifetime ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(11, new SWItem(SWItem.getDye(lifetime < maxLifetime ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.setLifetime(Math.min(maxLifetime, lifetime + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eActivation Time§8:§7 " + lifetime, clickType -> { new SimulatorAnvilGui<>(player, "Activation Time", lifetime + "", Integer::parseInt, integer -> { @@ -135,17 +135,17 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { lifetimeItem.getItemStack().setAmount(Math.max(1, Math.min(lifetime, 64))); inventory.setItem(20, lifetimeItem); - inventory.setItem(29, SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(29, new SWItem(SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.setLifetime(Math.max(0, lifetime - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); //Order int order = redstone.getOrder(); - inventory.setItem(13, SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(13, new SWItem(SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR"); SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eActivation Order§8:§7 " + order, clickType -> { @@ -160,9 +160,9 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { orderItem.getItemStack().setAmount(Math.max(1, Math.min(Math.abs(order), 30))); inventory.setItem(22, orderItem); - inventory.setItem(31, SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(31, new SWItem(SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneSettingsGui.java index 184d73a16..f8e6b3b83 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneSettingsGui.java @@ -55,7 +55,7 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); - })); + }).setCustomModelData(1)); // Material Chooser inventory.setItem(4, redstone.toItem(player, clickType -> { @@ -64,10 +64,10 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { // Base Tick int baseTicks = redstone.getBaseTick(); - inventory.setItem(9, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.changeBaseTicks(clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> { new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> { if (integer < 0) return false; @@ -78,20 +78,20 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { }); baseTick.getItemStack().setAmount(Math.max(1, Math.min(baseTicks, 64))); inventory.setItem(18, baseTick); - inventory.setItem(27, SWItem.getDye(baseTicks > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(27, new SWItem(SWItem.getDye(baseTicks > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { if (baseTicks - (clickType.isShiftClick() ? 5 : 1) < 0) { redstone.changeBaseTicks(-baseTicks); } else { redstone.changeBaseTicks(clickType.isShiftClick() ? -5 : -1); } SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); //Pos X - inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.move(clickType.isShiftClick() ? 5 : 1, 0, 0); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + redstone.getPosition().getBlockX(), clickType -> { new SimulatorAnvilGui<>(player, "X", redstone.getPosition().getBlockX() + "", Integer::parseInt, i -> { redstone.getPosition().setX(i); @@ -99,16 +99,16 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { return true; }, this).open(); })); - inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.move(clickType.isShiftClick() ? -5 : -1, 0, 0); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); //Pos Y - inventory.setItem(16, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.move(0, clickType.isShiftClick() ? 5 : 1, 0); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + redstone.getPosition().getBlockY(), clickType -> { new SimulatorAnvilGui<>(player, "Y", redstone.getPosition().getBlockY() + "", Integer::parseInt, i -> { redstone.getPosition().setY(i); @@ -116,16 +116,16 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { return true; }, this).open(); })); - inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.move(0, clickType.isShiftClick() ? -5 : -1, 0); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); //Pos Z - inventory.setItem(17, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.move(0, 0, clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + redstone.getPosition().getBlockZ(), clickType -> { new SimulatorAnvilGui<>(player, "Z", redstone.getPosition().getBlockZ() + "", Integer::parseInt, i -> { redstone.getPosition().setZ(i); @@ -133,9 +133,9 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { return true; }, this).open(); })); - inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.move(0, 0, clickType.isShiftClick() ? -5 : -1); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java index ccb004124..48b357256 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java @@ -47,7 +47,7 @@ public class SimulatorSettingsGui extends SimulatorBaseGui { // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); - })); + }).setCustomModelData(1)); // Material Chooser inventory.setItem(4, simulator.toItem(player, clickType -> { @@ -61,39 +61,39 @@ public class SimulatorSettingsGui extends SimulatorBaseGui { })); //Pos X - inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { simulator.move(clickType.isShiftClick() ? 5 : 1, 0, 0); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); inventory.setItem(24, new SWItem(Material.PAPER, "§eX", clickType -> { })); - inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { simulator.move(clickType.isShiftClick() ? -5 : -1, 0, 0); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); //Pos Y - inventory.setItem(16, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { simulator.move(0, clickType.isShiftClick() ? 5 : 1, 0); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); inventory.setItem(25, new SWItem(Material.PAPER, "§eY", clickType -> { })); - inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { simulator.move(0, clickType.isShiftClick() ? -5 : -1, 0); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); //Pos Z - inventory.setItem(17, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { simulator.move(0, 0, clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); inventory.setItem(26, new SWItem(Material.PAPER, "§eZ", clickType -> { })); - inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { simulator.move(0, 0, clickType.isShiftClick() ? -5 : -1); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java index 3520720eb..a9b660d53 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java @@ -81,12 +81,12 @@ public class SimulatorTNTGui extends SimulatorScrollGui { new SimulatorGroupGui(player, simulator, newParent, simulatorGui).open(); } } - })); + }).setCustomModelData(1)); inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { tnt.getPhases().clear(); SimulatorWatcher.update(simulator); - })); + }).setCustomModelData(1)); // Material Chooser inventory.setItem(4, tnt.toItem(player, clickType -> { @@ -95,11 +95,11 @@ public class SimulatorTNTGui extends SimulatorScrollGui { inventory.setItem(47, new SWItem(Material.REPEATER, "§eSettings", clickType -> { new SimulatorTNTSettingsGui(player, simulator, tnt, this).open(); - })); + }).setCustomModelData(1)); inventory.setItem(48, new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { tnt.setDisabled(!tnt.isDisabled()); SimulatorWatcher.update(simulator); - })); + }).setCustomModelData(1)); inventory.setItem(49, new SWItem(Material.CALIBRATED_SCULK_SENSOR, "§eCreate Stab", click -> { new SimulatorAnvilGui<>(player, "Depth Limit", "", Integer::parseInt, depthLimit -> { if (depthLimit <= 0) return false; @@ -107,17 +107,17 @@ public class SimulatorTNTGui extends SimulatorScrollGui { SimulatorWatcher.update(simulator); return true; }, null).open(); - })); + }).setCustomModelData(1)); inventory.setItem(50, new SWItem(Material.CHEST, parent.getElements().size() == 1 ? "§eMake Group" : "§eAdd another TNT to Group", clickType -> { TNTElement tntElement = new TNTElement(tnt.getPosition().clone()); tntElement.add(new TNTPhase()); parent.add(tntElement); new SimulatorGroupGui(player, simulator, parent, new SimulatorGui(player, simulator)).open(); SimulatorWatcher.update(simulator); - })); + }).setCustomModelData(1)); inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> { new SimulatorGroupChooserGui(player, simulator, tnt, tnt.getGroup(simulator), this).open(); - })); + }).setCustomModelData(1)); } @Override @@ -136,15 +136,15 @@ public class SimulatorTNTGui extends SimulatorScrollGui { new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { tntSetting.setCount(tntSetting.getCount() + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); - }), + }).setCustomModelData(3), tnt, new SWItem(SWItem.getDye(tntSetting.getCount() > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> { tntSetting.setCount(Math.max(1, tntSetting.getCount() - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }), + }).setCustomModelData(3), new SWItem(Material.ANVIL, "§eEdit Phase", clickType -> { new SimulatorTNTPhaseSettingsGui(player, simulator, this.tnt, tntSetting, this).open(); - }), + }).setCustomModelData(1), }; } @@ -153,12 +153,12 @@ public class SimulatorTNTGui extends SimulatorScrollGui { return new SWItem[]{ new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { addNewPhase(clickType.isShiftClick()); - }), + }).setCustomModelData(3), new SWItem(Material.GUNPOWDER, "§eTNT§8:§a New Phase", clickType -> { addNewPhase(false); - }), + }).setCustomModelData(1), new SWItem(SWItem.getDye(8), "§7", clickType -> { - }), + }).setCustomModelData(3), }; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java index 9bfc4fe58..fd78d18ac 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java @@ -60,7 +60,7 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); - })); + }).setCustomModelData(1)); // Material Chooser inventory.setItem(4, tntElement.toItem(player, clickType -> { @@ -72,14 +72,14 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { tntElement.getPhases().remove(tnt); back.open(); SimulatorWatcher.update(simulator); - })); + }).setCustomModelData(1)); //Count int count = tnt.getCount(); - inventory.setItem(9, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { tnt.setCount(count + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); SWItem countItem = new SWItem(Material.TNT, "§eCount§8:§7 " + count, clickType -> { new SimulatorAnvilGui<>(player, "Count", count + "", Integer::parseInt, integer -> { @@ -92,17 +92,17 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { countItem.getItemStack().setAmount(Math.max(1, Math.min(count, 64))); inventory.setItem(18, countItem); - inventory.setItem(27, SWItem.getDye(count > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(27, new SWItem(SWItem.getDye(count > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { tnt.setCount(Math.max(1, count - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); //Tick Offset int offset = tnt.getTickOffset(); - inventory.setItem(10, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(10, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { tnt.setTickOffset(offset + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> { new SimulatorAnvilGui<>(player, "Start at", offset + "", Integer::parseInt, integer -> { @@ -115,17 +115,17 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { offsetItem.getItemStack().setAmount(Math.max(1, Math.min(offset, 64))); inventory.setItem(19, offsetItem); - inventory.setItem(28, SWItem.getDye(offset > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(28, new SWItem(SWItem.getDye(offset > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { tnt.setTickOffset(Math.max(0, offset - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); //Lifetime int lifetime = tnt.getLifetime(); - inventory.setItem(11, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(11, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { tnt.setLifetime(lifetime + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eLifetime§8:§7 " + lifetime, clickType -> { new SimulatorAnvilGui<>(player, "Lifetime", lifetime + "", Integer::parseInt, integer -> { @@ -138,17 +138,17 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { lifetimeItem.getItemStack().setAmount(Math.max(1, Math.min(lifetime, 64))); inventory.setItem(20, lifetimeItem); - inventory.setItem(29, SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(29, new SWItem(SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { tnt.setLifetime(Math.max(1, lifetime - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); //Order int order = tnt.getOrder(); - inventory.setItem(13, SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(13, new SWItem(SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { tnt.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR"); SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eCalculation Order§8:§7 " + order, clickType -> { @@ -163,10 +163,10 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { orderItem.getItemStack().setAmount(Math.max(1, Math.min(Math.abs(order), 30))); inventory.setItem(22, orderItem); - inventory.setItem(31, SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(31, new SWItem(SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { tnt.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); //Jump SWItem jumpX = new SWItem(tnt.isXJump() ? Material.LIME_WOOL : Material.RED_WOOL, "§7TNT §eJump X§8: " + (tnt.isZJump() ? "§aon" : "§coff"), clickType -> { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java index 24dbb22e4..cd24bddbc 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java @@ -58,7 +58,7 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); - })); + }).setCustomModelData(1)); // Material Chooser List lore = new ArrayList<>(); @@ -74,10 +74,10 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { // Base Tick int baseTicks = tnt.getBaseTick(); - inventory.setItem(9, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { tnt.changeBaseTicks(clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> { new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> { if (integer < 0) return false; @@ -88,14 +88,14 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { }); baseTick.getItemStack().setAmount(Math.max(1, Math.min(baseTicks, 64))); inventory.setItem(18, baseTick); - inventory.setItem(27, SWItem.getDye(baseTicks > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(27, new SWItem(SWItem.getDye(baseTicks > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { if (baseTicks - (clickType.isShiftClick() ? 5 : 1) < 0) { tnt.changeBaseTicks(-baseTicks); } else { tnt.changeBaseTicks(clickType.isShiftClick() ? -5 : -1); } SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); // Subpixel Alignment inventory.setItem(21, new SWItem(Material.SUNFLOWER, "§7Align§8: §eCenter", clickType -> { @@ -135,10 +135,10 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { inventory.setItem(30, positivXItem); // Pos X - inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> { + inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> { tnt.move(clickType.isShiftClick() ? 0.0625 : 1, 0, 0); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + tnt.getPosition().getX(), clickType -> { new SimulatorAnvilGui<>(player, "X", tnt.getPosition().getX() + "", Double::parseDouble, d -> { tnt.getPosition().setX(d); @@ -146,16 +146,16 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { return true; }, this).open(); })); - inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { + inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { tnt.move(clickType.isShiftClick() ? -0.0625 : -1, 0, 0); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); // Pos Y - inventory.setItem(16, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> { + inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> { tnt.move(0, clickType.isShiftClick() ? 0.0625 : 1, 0); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + tnt.getPosition().getY(), clickType -> { new SimulatorAnvilGui<>(player, "Y", tnt.getPosition().getY() + "", Double::parseDouble, d -> { tnt.getPosition().setY(d); @@ -163,16 +163,16 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { return true; }, this).open(); })); - inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { + inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { tnt.move(0, clickType.isShiftClick() ? -0.0625 : -1, 0); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); // Pos Z - inventory.setItem(17, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> { + inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> { tnt.move(0, 0, clickType.isShiftClick() ? 0.0625 : 1); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + tnt.getPosition().getZ(), clickType -> { new SimulatorAnvilGui<>(player, "Z", tnt.getPosition().getZ() + "", Double::parseDouble, d -> { tnt.getPosition().setZ(d); @@ -180,9 +180,9 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { return true; }, this).open(); })); - inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { + inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { tnt.move(0, 0, clickType.isShiftClick() ? -0.0625 : -1); SimulatorWatcher.update(simulator); - }); + }).setCustomModelData(3)); } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorPageGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorPageGui.java index e3c3ccbd8..d3f24b568 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorPageGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorPageGui.java @@ -50,19 +50,19 @@ public abstract class SimulatorPageGui extends SimulatorBaseGui { headerAndFooter(); page = Math.min(page, maxPage()); - inventory.setItem(size - 9, SWItem.getDye(page > 0 ? 10 : 8), page > 0 ? (byte) 10 : (byte) 8, Core.MESSAGE.parse(page > 0 ? "SWLISINV_PREVIOUS_PAGE_ACTIVE" : "SWLISINV_PREVIOUS_PAGE_INACTIVE", player), clickType -> { + inventory.setItem(size - 9, new SWItem(SWItem.getDye(page > 0 ? 10 : 8), page > 0 ? (byte) 10 : (byte) 8, Core.MESSAGE.parse(page > 0 ? "SWLISINV_PREVIOUS_PAGE_ACTIVE" : "SWLISINV_PREVIOUS_PAGE_INACTIVE", player), clickType -> { if (page > 0) { page--; open(); } - }); + }).setCustomModelData(1)); boolean hasNext = page < maxPage() - (data.size() % (size - 18) == 0 ? 1 : 0); - inventory.setItem(size - 1, SWItem.getDye(hasNext ? 10 : 8), hasNext ? (byte) 10 : (byte) 8, Core.MESSAGE.parse(hasNext ? "SWLISINV_NEXT_PAGE_ACTIVE" : "SWLISINV_NEXT_PAGE_INACTIVE", player), clickType -> { + inventory.setItem(size - 1, new SWItem(SWItem.getDye(hasNext ? 10 : 8), hasNext ? (byte) 10 : (byte) 8, Core.MESSAGE.parse(hasNext ? "SWLISINV_NEXT_PAGE_ACTIVE" : "SWLISINV_NEXT_PAGE_INACTIVE", player), clickType -> { if (hasNext) { page++; open(); } - }); + }).setCustomModelData(2)); int minElement = page * (size - 18); int maxElement = Math.min(data.size(), (page + 1) * (size - 18)); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorScrollGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorScrollGui.java index a4cfbb5df..6538196a3 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorScrollGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorScrollGui.java @@ -50,19 +50,19 @@ public abstract class SimulatorScrollGui extends SimulatorBaseGui { headerAndFooter(); scroll = maxScroll(); - inventory.setItem(size - 9, SWItem.getDye(scroll > 0 ? 10 : 8), scroll > 0 ? (byte) 10 : (byte) 8, Core.MESSAGE.parse(scroll > 0 ? "SWLISINV_PREVIOUS_PAGE_ACTIVE" : "SWLISINV_PREVIOUS_PAGE_INACTIVE", player), clickType -> { + inventory.setItem(size - 9, new SWItem(SWItem.getDye(scroll > 0 ? 10 : 8), scroll > 0 ? (byte) 10 : (byte) 8, Core.MESSAGE.parse(scroll > 0 ? "SWLISINV_PREVIOUS_PAGE_ACTIVE" : "SWLISINV_PREVIOUS_PAGE_INACTIVE", player), clickType -> { if (scroll > 0) { scroll = Math.max(0, scroll - 9); open(); } - }); + }).setCustomModelData(1)); boolean hasNext = (data.size() + 1) - scroll > 9; - inventory.setItem(size - 1, SWItem.getDye(hasNext ? 10 : 8), hasNext ? (byte) 10 : (byte) 8, Core.MESSAGE.parse(hasNext ? "SWLISINV_NEXT_PAGE_ACTIVE" : "SWLISINV_NEXT_PAGE_INACTIVE", player), clickType -> { + inventory.setItem(size - 1, new SWItem(SWItem.getDye(hasNext ? 10 : 8), hasNext ? (byte) 10 : (byte) 8, Core.MESSAGE.parse(hasNext ? "SWLISINV_NEXT_PAGE_ACTIVE" : "SWLISINV_NEXT_PAGE_INACTIVE", player), clickType -> { if (hasNext) { scroll = Math.min(scroll + 9, data.size() + 1 - 9); open(); } - }); + }).setCustomModelData(2)); for (int i = 0; i < 9; i++) { if (scroll + i < data.size()) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWItem.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWItem.java index 1f9c98137..2220c471f 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWItem.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWItem.java @@ -145,62 +145,76 @@ public class SWItem { return item; } - private void hideAttributes() { - if (itemMeta == null) return; + private SWItem hideAttributes() { + if (itemMeta == null) return this; for (ItemFlag flag : EnumSet.allOf(ItemFlag.class)) { itemMeta.addItemFlags(flag); } + return this; } public ItemStack getItemStack() { return itemStack; } - public void setItemStack(ItemStack itemStack) { + public SWItem setItemStack(ItemStack itemStack) { this.itemStack = itemStack; itemMeta = itemStack.getItemMeta(); hideAttributes(); + return this; } public ItemMeta getItemMeta() { return itemMeta; } - public void setItemMeta(ItemMeta itemMeta) { + public SWItem setItemMeta(ItemMeta itemMeta) { this.itemMeta = itemMeta; itemStack.setItemMeta(itemMeta); hideAttributes(); + return this; } public InvCallback getCallback() { return callback; } - public void setCallback(InvCallback callback) { + public SWItem setCallback(InvCallback callback) { this.callback = callback; + return this; } - public void setName(String name) { + public SWItem setName(String name) { itemMeta.setDisplayName(name); itemStack.setItemMeta(itemMeta); + return this; } - public void setLore(List lore) { + public SWItem setLore(List lore) { itemMeta.setLore(lore); itemStack.setItemMeta(itemMeta); + return this; } - public void setLore(String... lore) { + public SWItem setLore(String... lore) { itemMeta.setLore(Arrays.stream(lore).collect(Collectors.toList())); itemStack.setItemMeta(itemMeta); + return this; } - public void setEnchanted(boolean enchanted) { + public SWItem setEnchanted(boolean enchanted) { if (enchanted){ itemMeta.addEnchant(TrickyTrialsWrapper.impl.getUnbreakingEnchantment() , 10, true); } else { itemMeta.removeEnchant(TrickyTrialsWrapper.impl.getUnbreakingEnchantment()); } itemStack.setItemMeta(itemMeta); + return this; + } + + public SWItem setCustomModelData(int customModelData) { + itemMeta.setCustomModelData(customModelData); + itemStack.setItemMeta(itemMeta); + return this; } } From fa13872f2234fa827de0212bf0e2cba6869bb085 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Mon, 21 Apr 2025 00:05:50 +0200 Subject: [PATCH 014/153] Add SWListInv --- .../src/de/steamwar/inventory/SWListInv.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java index 8851081fd..a5967dd4a 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java @@ -63,28 +63,28 @@ public class SWListInv extends SWInventory { if (sizeBiggerMax()) { if (page != 0) { - setItem(45, SWItem.getDye(10), (byte) 10, Core.MESSAGE.parse("SWLISINV_PREVIOUS_PAGE_ACTIVE", player), (ClickType click) -> { + setItem(45, new SWItem(SWItem.getDye(10), (byte) 10, Core.MESSAGE.parse("SWLISINV_PREVIOUS_PAGE_ACTIVE", player), (ClickType click) -> { page--; open(); - }); + }).setCustomModelData(1)); } else { - setItem(45, SWItem.getDye(8), (byte) 8, Core.MESSAGE.parse("SWLISINV_PREVIOUS_PAGE_INACTIVE", player), (ClickType click) -> { - }); + setItem(45, new SWItem(SWItem.getDye(8), (byte) 8, Core.MESSAGE.parse("SWLISINV_PREVIOUS_PAGE_INACTIVE", player), (ClickType click) -> { + }).setCustomModelData(1)); } if (page < elements.size() / 45 - (elements.size() % 45 == 0 ? 1 : 0)) { - setItem(53, SWItem.getDye(10), (byte) 10, Core.MESSAGE.parse("SWLISINV_NEXT_PAGE_ACTIVE", player), (ClickType click) -> { + setItem(53, new SWItem(SWItem.getDye(10), (byte) 10, Core.MESSAGE.parse("SWLISINV_NEXT_PAGE_ACTIVE", player), (ClickType click) -> { page++; open(); - }); + }).setCustomModelData(2)); } else { - setItem(53, SWItem.getDye(8), (byte) 8, Core.MESSAGE.parse("SWLISINV_NEXT_PAGE_INACTIVE", player), (ClickType click) -> { - }); + setItem(53, new SWItem(SWItem.getDye(8), (byte) 8, Core.MESSAGE.parse("SWLISINV_NEXT_PAGE_INACTIVE", player), (ClickType click) -> { + }).setCustomModelData(2)); } } else if (!dynamicSize) { - setItem(45, SWItem.getDye(8), (byte) 8, Core.MESSAGE.parse("SWLISINV_PREVIOUS_PAGE_INACTIVE", player), (ClickType click) -> { - }); - setItem(53, SWItem.getDye(8), (byte) 8, Core.MESSAGE.parse("SWLISINV_NEXT_PAGE_INACTIVE", player), (ClickType click) -> { - }); + setItem(45, new SWItem(SWItem.getDye(8), (byte) 8, Core.MESSAGE.parse("SWLISINV_PREVIOUS_PAGE_INACTIVE", player), (ClickType click) -> { + }).setCustomModelData(1)); + setItem(53, new SWItem(SWItem.getDye(8), (byte) 8, Core.MESSAGE.parse("SWLISINV_NEXT_PAGE_INACTIVE", player), (ClickType click) -> { + }).setCustomModelData(2)); } int ipageLimit = elements.size() - page * 45; From 6eb01a61b14ce57173135488fd1797c1f1611df0 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Mon, 21 Apr 2025 00:16:49 +0200 Subject: [PATCH 015/153] Update every Back item to use the new texture --- .../steamwar/bausystem/features/gui/editor/BauGuiEditor.java | 2 +- .../features/loader/elements/LoaderInteractionElement.java | 4 ++-- .../bausystem/features/loader/elements/impl/LoaderWait.java | 2 +- .../bausystem/features/slaves/laufbau/LaufbauSettings.java | 2 +- .../de/steamwar/bausystem/features/util/MaterialCommand.java | 4 ++-- .../src/de/steamwar/inventory/SchematicSelector.java | 2 +- .../src/de/steamwar/teamserver/command/MaterialCommand.java | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/gui/editor/BauGuiEditor.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/gui/editor/BauGuiEditor.java index e40b01f3e..acb3377a9 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/gui/editor/BauGuiEditor.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/gui/editor/BauGuiEditor.java @@ -74,7 +74,7 @@ public class BauGuiEditor implements Listener { inv.setItem(mapping.getSize() + 5, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("GUI_EDITOR_ITEM_TRASH", p), Arrays.asList(BauSystem.MESSAGE.parse("GUI_EDITOR_ITEM_TRASH_LORE", p)), false, clickType -> { }).getItemStack()); inv.setItem(mapping.getSize() + 6, new SWItem(TrickyTrialsWrapper.impl.getTurtleScute(), BauSystem.MESSAGE.parse("GUI_EDITOR_ITEM_MORE", p)).getItemStack()); - inv.setItem(mapping.getSize() + 8, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("GUI_EDITOR_ITEM_CLOSE", p)).getItemStack()); + inv.setItem(mapping.getSize() + 8, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("GUI_EDITOR_ITEM_CLOSE", p)).setCustomModelData(1).getItemStack()); p.openInventory(inv); p.getOpenInventory().setCursor(cursor == null ? new SWItem().getItemStack() : cursor); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderInteractionElement.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderInteractionElement.java index 67539fd85..25288955b 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderInteractionElement.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderInteractionElement.java @@ -113,7 +113,7 @@ public abstract class LoaderInteractionElement & LoaderSetting }); listInv.setItem(48, new SWItem(Material.ARROW, "§7Back", clickType -> { backAction.run(); - })); + }).setCustomModelData(1)); listInv.setItem(50, new SWItem(Material.GHAST_SPAWN_EGG, "§7Insert another Setting", clickType -> { elements.add(defaultSetting); extraPower.add(0); @@ -150,7 +150,7 @@ public abstract class LoaderInteractionElement & LoaderSetting SWInventory swInventory = new SWInventory(player, guiSize, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_TITLE", player)); for (int i = guiSize - 9; i < guiSize; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7", clickType -> {})); - swInventory.setItem(guiSize - 9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> back.run()); + swInventory.setItem(guiSize - 9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).setCustomModelData(1).getItemStack(), clickType -> back.run()); swInventory.setItem(guiSize - 5, new SWItem(Material.WOODEN_AXE, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_COPY", player)).getItemStack(), clickType -> { SWAnvilInv swAnvilInv = new SWAnvilInv(player, BauSystem.MESSAGE.parse("LOADER_GUI_COPY_TITLE", player), "1"); swAnvilInv.setCallback(s -> { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderWait.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderWait.java index 41fcb9773..394963b13 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderWait.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderWait.java @@ -60,7 +60,7 @@ public class LoaderWait implements LoaderElement { public void click(Player player, Runnable backAction) { SWInventory swInventory = new SWInventory(player, 18, BauSystem.MESSAGE.parse("LOADER_GUI_WAIT_TITLE", player)); for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); - swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_WAIT_BACK", player)).getItemStack(), clickType -> backAction.run()); + swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_WAIT_BACK", player)).setCustomModelData(1).getItemStack(), clickType -> backAction.run()); swInventory.setItem(3, new SWItem(SWItem.getDye(1), BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_REMOVE_ONE", player), Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_REMOVE_ONE_SHIFT", player)), false, clickType -> {}).getItemStack(), clickType -> { delay -= clickType.isShiftClick() ? 5 : 1; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauSettings.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauSettings.java index c52f9a1da..e9ff017f8 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauSettings.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauSettings.java @@ -91,7 +91,7 @@ public class LaufbauSettings { }); inv.setItem(49, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_GUI_BACK", p), clickType -> { open(); - })); + }).setCustomModelData(1)); inv.open(); } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/MaterialCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/MaterialCommand.java index 7893b8c4b..a5a152430 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/MaterialCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/MaterialCommand.java @@ -202,9 +202,9 @@ public class MaterialCommand extends SWCommand implements Listener { private void searchGUI(Player p) { SWInventory swInventory = new SWInventory(p, 54, BauSystem.MESSAGE.parse("MATERIAL_SEARCH", p)); Search search = searchMap.get(p); - swInventory.setItem(45, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("MATERIAL_BACK", p), clickType -> { + swInventory.setItem(0, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("MATERIAL_BACK", p), clickType -> { materialGUI(p); - })); + }).setCustomModelData(1)); swInventory.setItem(10, new SWItem(Material.NAME_TAG, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_NAME", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.name), clickType -> { SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_NAME", p), search.name); swAnvilInv.setCallback(s -> { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java index 648247bb7..b6fe5c141 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java @@ -113,7 +113,7 @@ public class SchematicSelector { List> list = new ArrayList<>(); if(depth != 0) { - list.add(new SWListInv.SWListEntry<>(new SWItem(Material.ARROW, Core.MESSAGE.parse("SCHEM_SELECTOR_BACK", player), clickType -> {}), null)); + list.add(new SWListInv.SWListEntry<>(new SWItem(Material.ARROW, Core.MESSAGE.parse("SCHEM_SELECTOR_BACK", player), clickType -> {}).setCustomModelData(1), null)); } for (SchematicNode node : nodes) { diff --git a/Teamserver/src/de/steamwar/teamserver/command/MaterialCommand.java b/Teamserver/src/de/steamwar/teamserver/command/MaterialCommand.java index d58830626..cea302789 100644 --- a/Teamserver/src/de/steamwar/teamserver/command/MaterialCommand.java +++ b/Teamserver/src/de/steamwar/teamserver/command/MaterialCommand.java @@ -206,9 +206,9 @@ public class MaterialCommand extends SWCommand implements Listener { private void searchGUI(Player p) { SWInventory swInventory = new SWInventory(p, 54, Builder.MESSAGE.parse("MATERIAL_SEARCH", p)); Search search = searchMap.get(p); - swInventory.setItem(45, new SWItem(Material.ARROW, Builder.MESSAGE.parse("MATERIAL_BACK", p), clickType -> { + swInventory.setItem(0, new SWItem(Material.ARROW, Builder.MESSAGE.parse("MATERIAL_BACK", p), clickType -> { materialGUI(p); - })); + }).setCustomModelData(1)); swInventory.setItem(10, new SWItem(Material.NAME_TAG, Builder.MESSAGE.parse("MATERIAL_SEARCH_NAME", p) + Builder.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.name), clickType -> { SWAnvilInv swAnvilInv = new SWAnvilInv(p, Builder.MESSAGE.parse("MATERIAL_SEARCH_NAME", p), search.name); swAnvilInv.setCallback(s -> { From b0be06136d96ea6415457136cb0bffcf9accc150 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 18 May 2025 13:31:14 +0200 Subject: [PATCH 016/153] Add 'ergebnis' field to EventFights data model and update logic Introduced a new 'ergebnis' field to the EventFights data model to handle fight results. Updated the logic to support processing and updating this field when provided. This ensures better tracking and management of event fight outcomes. --- WebsiteBackend/src/de/steamwar/routes/EventFights.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/WebsiteBackend/src/de/steamwar/routes/EventFights.kt b/WebsiteBackend/src/de/steamwar/routes/EventFights.kt index 1f0e63c5a..bcdb1b6eb 100644 --- a/WebsiteBackend/src/de/steamwar/routes/EventFights.kt +++ b/WebsiteBackend/src/de/steamwar/routes/EventFights.kt @@ -68,7 +68,8 @@ data class UpdateEventFight( val spielmodus: String? = null, val map: String? = null, val group: Int? = null, - val spectatePort: Int? = null + val spectatePort: Int? = null, + val ergebnis: Int? = null, ) @Serializable @@ -133,6 +134,11 @@ fun Route.configureEventFightRoutes() { fight.groupId = updateFight.group } } + + if (updateFight.ergebnis != null) { + fight.ergebnis = updateFight.ergebnis + } + fight.update(start, spielmodus, map, teamBlue, teamRed, spectatePort) call.respond(HttpStatusCode.OK, ResponseEventFight(fight)) } From 8768fd7d8158e1697f39adb9919b2a4c4d634a0c Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 22 May 2025 19:42:49 +0200 Subject: [PATCH 017/153] Refactor event handling and group assignment logic Replaced `fight.event` with `event.eventID` for consistency and improved event handling. Adjusted `setGroup` to accept `Integer` instead of `EventGroup` to simplify group assignment logic. Removed unused `event` field in `CreateEventFight` and streamlined related processing. --- CommonCore/SQL/src/de/steamwar/sql/EventFight.java | 6 +++--- WebsiteBackend/src/de/steamwar/routes/EventFights.kt | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/EventFight.java b/CommonCore/SQL/src/de/steamwar/sql/EventFight.java index d23e74117..72b19b425 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/EventFight.java +++ b/CommonCore/SQL/src/de/steamwar/sql/EventFight.java @@ -153,9 +153,9 @@ public class EventFight implements Comparable { setFight.update(fight, fightID); } - public void setGroup(EventGroup group) { - setGroup.update(group.getId(), fightID); - this.groupId = group.getId(); + public void setGroup(Integer group) { + setGroup.update(group, fightID); + this.groupId = group; } public boolean hasFinished() { diff --git a/WebsiteBackend/src/de/steamwar/routes/EventFights.kt b/WebsiteBackend/src/de/steamwar/routes/EventFights.kt index bcdb1b6eb..4823619f1 100644 --- a/WebsiteBackend/src/de/steamwar/routes/EventFights.kt +++ b/WebsiteBackend/src/de/steamwar/routes/EventFights.kt @@ -74,7 +74,6 @@ data class UpdateEventFight( @Serializable data class CreateEventFight( - val event: Int, val spielmodus: String, val map: String, val blueTeam: Int, @@ -91,6 +90,8 @@ fun Route.configureEventFightRoutes() { call.respond(EventFight.getEvent(event.eventID).map { ResponseEventFight(it) }) } post { + val event = call.receiveEvent() ?: return@post + val fight = call.receiveNullable() if (fight == null) { call.respond(HttpStatusCode.BadRequest, ResponseError("Invalid body")) @@ -98,7 +99,7 @@ fun Route.configureEventFightRoutes() { } val eventFight = EventFight.create( - fight.event, + event.eventID, Timestamp.from(Instant.ofEpochMilli(fight.start)), fight.spielmodus, fight.map, @@ -129,9 +130,9 @@ fun Route.configureEventFightRoutes() { if (updateFight.group != null) { if (updateFight.group == -1) { - fight.groupId = null + fight.setGroup(null) } else { - fight.groupId = updateFight.group + fight.setGroup(updateFight.group) } } From c35d4741a0dd19080f68761fb750383c64acb86b Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 28 May 2025 14:19:21 +0200 Subject: [PATCH 018/153] Add TexturePackSystem --- .../steamwar/velocitycore/VelocityCore.java | 1 + .../listeners/TexturePackSystem.java | 105 ++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 VelocityCore/src/de/steamwar/velocitycore/listeners/TexturePackSystem.java diff --git a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java index 3cec098bb..e80ad5fcb 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java +++ b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java @@ -153,6 +153,7 @@ public class VelocityCore implements ReloadablePlugin { new CheckListener(); new IPSanitizer(); new VersionAnnouncer(); + new TexturePackSystem(); local = new Node.LocalNode(); if(MAIN_SERVER) { diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/TexturePackSystem.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/TexturePackSystem.java new file mode 100644 index 000000000..46da12daf --- /dev/null +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/TexturePackSystem.java @@ -0,0 +1,105 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.velocitycore.listeners; + +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.player.ServerPostConnectEvent; +import com.velocitypowered.api.proxy.player.ResourcePackInfo; +import de.steamwar.velocitycore.VelocityCore; +import net.kyori.adventure.text.Component; + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.util.Map; +import java.util.TreeMap; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +// https://jd.papermc.io/velocity/3.4.0/com/velocitypowered/api/proxy/player/ResourcePackInfo.Builder.html#setHash(byte%5B%5D) +public class TexturePackSystem extends BasicListener { + + private static final File PACKS_DIR = new File("/var/www/packs"); + private static final String BASE_ULR = "https://packs.steamwar.de/"; + private TreeMap protocolVersionToPackVersion = new TreeMap<>(); + + public TexturePackSystem() { + // https://minecraft.wiki/w/Pack_format#List_of_resource_pack_formats + // https://minecraft.wiki/w/Minecraft_Wiki:Projects/wiki.vg_merge/Protocol_version_numbers + protocolVersionToPackVersion.put(759, 9); + protocolVersionToPackVersion.put(761, 12); + protocolVersionToPackVersion.put(762, 13); + protocolVersionToPackVersion.put(763, 15); + protocolVersionToPackVersion.put(764, 18); + protocolVersionToPackVersion.put(765, 22); + protocolVersionToPackVersion.put(766, 32); + protocolVersionToPackVersion.put(767, 34); + protocolVersionToPackVersion.put(768, 42); + protocolVersionToPackVersion.put(769, 46); + protocolVersionToPackVersion.put(770, 55); + } + + @Subscribe + public void onLogin(ServerPostConnectEvent event) { + if (event.getPreviousServer() != null) { + return; + } + VelocityCore.schedule(() -> { + int playerVersion = event.getPlayer().getProtocolVersion().getProtocol(); + File selectedPack = null; + while (selectedPack == null) { + Map.Entry pack = protocolVersionToPackVersion.floorEntry(playerVersion); + if (pack == null) return; + + for (File file : PACKS_DIR.listFiles()) { + if (file.getName().startsWith(pack.getValue() + "_")) { + selectedPack = file; + break; + } + } + + playerVersion--; + } + + String fileName = selectedPack.getName(); + fileName = fileName.substring(fileName.indexOf('_') + 1, fileName.lastIndexOf('.')); + byte[] hash = hexStringToByteArray(fileName); + + ResourcePackInfo resourcePackInfo = VelocityCore.getProxy().createResourcePackBuilder(BASE_ULR + selectedPack.getName()) + .setId(UUID.nameUUIDFromBytes(fileName.getBytes(StandardCharsets.UTF_8))) + .setHash(hash) + .setShouldForce(false) + .setPrompt(Component.text("The SteamWar TexturePack improves GUIs!")) + .build(); + event.getPlayer().sendResourcePacks(resourcePackInfo); + }).delay(500, TimeUnit.MILLISECONDS).schedule(); + } + + public static byte[] hexStringToByteArray(String s) { + int len = s.length(); + byte[] data = new byte[len / 2]; + + for (int i = 0; i < len; i += 2) { + data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + + Character.digit(s.charAt(i+1), 16)); + } + + return data; + } +} From a5bb62590ca66dcd9aca71bf8ac185653641867b Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 28 May 2025 23:57:29 +0200 Subject: [PATCH 019/153] Refactor page routing and point calculation logic Streamlined the `page` routing structure by optimizing branch and file handling, introducing a reusable `filesInDirectory` method, and cleaning up redundancies. Enhanced `EventGroup` point calculation with incremental updates, new helper methods (`getTeams`, `getTeamsId`), and better handling of unfinished fights. --- .../SQL/src/de/steamwar/sql/EventGroup.java | 34 +-- .../src/de/steamwar/routes/EventFights.kt | 6 +- WebsiteBackend/src/de/steamwar/routes/Page.kt | 195 ++++++++++-------- 3 files changed, 130 insertions(+), 105 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/EventGroup.java b/CommonCore/SQL/src/de/steamwar/sql/EventGroup.java index 166e7eb15..689347659 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/EventGroup.java +++ b/CommonCore/SQL/src/de/steamwar/sql/EventGroup.java @@ -23,10 +23,9 @@ import de.steamwar.sql.internal.*; import lombok.Getter; import lombok.Setter; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; @Getter @Setter @@ -94,6 +93,15 @@ public class EventGroup { return EventFight.get(this); } + public Set getTeamsId() { + return getFights().stream().flatMap(fight -> Stream.of(fight.getTeamBlue(), fight.getTeamRed())) + .collect(Collectors.toSet()); + } + + public Set getTeams() { + return getTeamsId().stream().map(Team::get).collect(Collectors.toSet()); + } + public Optional getLastFight() { return EventFight.getLast(this); } @@ -104,13 +112,16 @@ public class EventGroup { public Map calculatePoints() { if (points == null) { - Map teams = new HashMap<>(); - points = new HashMap<>(); + Map p = getTeamsId().stream().collect(Collectors.toMap(team -> team, team -> 0)); for (EventFight fight : getFights()) { int blueTeamAdd = 0; int redTeamAdd = 0; + if (!fight.hasFinished()) { + continue; + } + switch (fight.getErgebnis()) { case 1: blueTeamAdd += pointsPerWin; @@ -128,19 +139,18 @@ public class EventGroup { break; } - Team blueTeam = teams.computeIfAbsent(fight.getTeamBlue(), Team::get); - Team redTeam = teams.computeIfAbsent(fight.getTeamRed(), Team::get); - - points.put(blueTeam, points.getOrDefault(blueTeam, 0) + blueTeamAdd); - points.put(redTeam, points.getOrDefault(redTeam, 0) + redTeamAdd); + p.put(fight.getTeamBlue(), p.get(fight.getTeamBlue()) + blueTeamAdd); + p.put(fight.getTeamRed(), p.get(fight.getTeamRed()) + redTeamAdd); } + + points = p.entrySet().stream().collect(Collectors.toMap(integerIntegerEntry -> Team.get(integerIntegerEntry.getKey()), Map.Entry::getValue)); } return points; } public void update(String name, EventGroupType type, int pointsPerWin, int pointsPerLoss, int pointsPerDraw) { - update.update(id, name, type, pointsPerWin, pointsPerLoss, pointsPerDraw); + update.update(name, type, pointsPerWin, pointsPerLoss, pointsPerDraw, id); this.name = name; this.type = type; this.pointsPerWin = pointsPerWin; diff --git a/WebsiteBackend/src/de/steamwar/routes/EventFights.kt b/WebsiteBackend/src/de/steamwar/routes/EventFights.kt index 4823619f1..d19746863 100644 --- a/WebsiteBackend/src/de/steamwar/routes/EventFights.kt +++ b/WebsiteBackend/src/de/steamwar/routes/EventFights.kt @@ -40,7 +40,8 @@ data class ResponseEventFight( val start: Long, val ergebnis: Int, val spectatePort: Int?, - val group: ResponseGroups? + val group: ResponseGroups?, + val hasFinished: Boolean ) { constructor(eventFight: EventFight) : this( eventFight.fightID, @@ -51,7 +52,8 @@ data class ResponseEventFight( eventFight.startTime.time, eventFight.ergebnis, eventFight.spectatePort, - eventFight.group.orElse(null)?.let { ResponseGroups(it) } + eventFight.group.orElse(null)?.let { ResponseGroups(it, short = true) }, + eventFight.hasFinished() ) } diff --git a/WebsiteBackend/src/de/steamwar/routes/Page.kt b/WebsiteBackend/src/de/steamwar/routes/Page.kt index 6f9a9fc4a..139814c75 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Page.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Page.kt @@ -24,7 +24,6 @@ import de.steamwar.plugins.SWAuthPrincipal import de.steamwar.plugins.SWPermissionCheck import de.steamwar.sql.UserPerm import io.ktor.client.* -import io.ktor.client.call.* import io.ktor.client.engine.java.* import io.ktor.client.plugins.* import io.ktor.client.plugins.contentnegotiation.* @@ -37,9 +36,7 @@ import io.ktor.server.auth.* import io.ktor.server.request.* import io.ktor.server.response.* import io.ktor.server.routing.* -import io.ktor.util.reflect.* import kotlinx.serialization.Serializable -import kotlinx.serialization.encodeToString import kotlinx.serialization.json.* import java.util.Base64 @@ -113,65 +110,42 @@ fun Route.configurePage() { } } + suspend fun filesInDirectory(path: String, branch: String = "master", fileFilter: (name: String) -> Boolean = { true }): List { + val filesToCheck = mutableListOf(path) + val files = mutableListOf() + + while (filesToCheck.isNotEmpty()) { + val path = filesToCheck.removeAt(0) + val res = client.get("repos/SteamWar/Website/contents/$path?ref=$branch") + val fileJson = Json.parseToJsonElement(res.bodyAsText()) + + if (fileJson is JsonArray) { + fileJson.forEach { + val obj = it.jsonObject + if (obj["type"]?.jsonPrimitive?.content == "dir") { + filesToCheck.add(obj["path"]?.jsonPrimitive?.content!!) + } else if (obj["type"]?.jsonPrimitive?.content == "file" && fileFilter(obj["name"]!!.jsonPrimitive.content)) { + files.add(PageResponseList(obj, pathPageIdMap.computeIfAbsent(obj["path"]?.jsonPrimitive?.content!!) { pageId++ })) + } + } + } else { + files.add(PageResponseList(fileJson.jsonObject, pathPageIdMap.computeIfAbsent(fileJson.jsonObject["path"]?.jsonPrimitive?.content!!) { pageId++ })) + } + } + + return files + } + route("page") { install(SWPermissionCheck) { permission = UserPerm.MODERATION } get { val branch = call.request.queryParameters["branch"] ?: "master" - val filesToCheck = mutableListOf("src/content") - val files = mutableListOf() - while (filesToCheck.isNotEmpty()) { - val path = filesToCheck.removeAt(0) - val res = client.get("repos/SteamWar/Website/contents/$path?ref=$branch") - val fileJson = Json.parseToJsonElement(res.bodyAsText()) - - if (fileJson is JsonArray) { - fileJson.forEach { - val obj = it.jsonObject - if (obj["type"]?.jsonPrimitive?.content == "dir") { - filesToCheck.add(obj["path"]?.jsonPrimitive?.content!!) - } else if (obj["type"]?.jsonPrimitive?.content == "file" && (obj["name"]?.jsonPrimitive?.content?.endsWith(".md") == true || obj["name"]?.jsonPrimitive?.content?.endsWith(".json") == true)) { - files.add(PageResponseList(obj, pathPageIdMap.computeIfAbsent(obj["path"]?.jsonPrimitive?.content!!) { pageId++ })) - } - } - } else { - files.add(PageResponseList(fileJson.jsonObject, pathPageIdMap.computeIfAbsent(fileJson.jsonObject["path"]?.jsonPrimitive?.content!!) { pageId++ })) - } - } - - call.respond(files) - } - get("branch") { - val res = client.get("repos/SteamWar/Website/branches") - call.respond(res.status, Json.parseToJsonElement(res.bodyAsText()).jsonArray.map { it.jsonObject["name"]?.jsonPrimitive?.content!! }) - } - post("branch") { - @Serializable - data class CreateGiteaBranchRequest(val new_branch_name: String, val old_branch_name: String) - - val branch = call.receive().branch - val res = client.post("repos/SteamWar/Website/branches") { - contentType(ContentType.Application.Json) - setBody(CreateGiteaBranchRequest(branch, "master")) - } - - - @Serializable - data class CreateGiteaMergeRequest(val base: String, val head: String, val title: String) - - client.post("repos/SteamWar/Website/pulls") { - contentType(ContentType.Application.Json) - setBody(CreateGiteaMergeRequest("master", branch, "Merge branch $branch")) - } - - call.respond(res.status) - } - delete("branch") { - val branch = call.receive().branch - val res = client.delete("repos/SteamWar/Website/branches/$branch") - call.respond(res.status) + call.respond(filesInDirectory("/src/content", branch) { + it.endsWith(".md") || it.endsWith(".json") + }) } post { @Serializable @@ -197,55 +171,94 @@ fun Route.configurePage() { """.trimIndent().toByteArray()), call.request.queryParameters["branch"] ?: "master", Identity(call.principal()!!.user.userName, "admin-tool@steamwar.de" - ))) + ))) } call.respond(res.status) } - get("{id}") { - val id = call.parameters["id"]?.toIntOrNull() ?: return@get call.respond(HttpStatusCode.BadRequest, "Invalid id") - val path = pathPageIdMap.entries.find { it.value == id }?.key ?: return@get call.respond(HttpStatusCode.NotFound, "Page not found") - - val branch = call.request.queryParameters["branch"] ?: "master" - val res = client.get("repos/SteamWar/Website/contents/$path?ref=$branch") - val fileJson = Json.parseToJsonElement(res.bodyAsText()) - if (fileJson is JsonArray) { - return@get call.respond(HttpStatusCode.BadRequest, "Invalid id") + route("branch") { + get { + val res = client.get("repos/SteamWar/Website/branches") + call.respond(res.status, Json.parseToJsonElement(res.bodyAsText()).jsonArray.map { it.jsonObject["name"]?.jsonPrimitive?.content!! }) } + post { + @Serializable + data class CreateGiteaBranchRequest(val new_branch_name: String, val old_branch_name: String) - val file = PageResponse(fileJson.jsonObject, id) - call.respond(file) + val branch = call.receive().branch + val res = client.post("repos/SteamWar/Website/branches") { + contentType(ContentType.Application.Json) + setBody(CreateGiteaBranchRequest(branch, "master")) + } + + + @Serializable + data class CreateGiteaMergeRequest(val base: String, val head: String, val title: String) + + client.post("repos/SteamWar/Website/pulls") { + contentType(ContentType.Application.Json) + setBody(CreateGiteaMergeRequest("master", branch, "Merge branch $branch")) + } + + call.respond(res.status) + } + delete { + val branch = call.receive().branch + val res = client.delete("repos/SteamWar/Website/branches/$branch") + call.respond(res.status) + } } + route("{id}") { + get { + val id = call.parameters["id"]?.toIntOrNull() ?: return@get call.respond(HttpStatusCode.BadRequest, "Invalid id") + val path = pathPageIdMap.entries.find { it.value == id }?.key ?: return@get call.respond(HttpStatusCode.NotFound, "Page not found") - delete("{id}") { - val data = call.receive() + val branch = call.request.queryParameters["branch"] ?: "master" + val res = client.get("repos/SteamWar/Website/contents/$path?ref=$branch") + val fileJson = Json.parseToJsonElement(res.bodyAsText()) + if (fileJson is JsonArray) { + return@get call.respond(HttpStatusCode.BadRequest, "Invalid id") + } - val path = pathPageIdMap.entries.find { it.value == call.parameters["id"]?.toIntOrNull() }?.key ?: return@delete call.respond(HttpStatusCode.NotFound, "Page not found") - val branch = call.request.queryParameters["branch"] ?: "master" - - @Serializable - data class DeleteGiteaPageRequest(val sha: String, val message: String, val branch: String, val author: Identity) - - val res = client.delete("repos/SteamWar/Website/contents/$path") { - contentType(ContentType.Application.Json) - setBody(DeleteGiteaPageRequest(data.sha, data.message, branch, Identity(call.principal()!!.user.userName, "admin-tool@steamwar.de"))) + val file = PageResponse(fileJson.jsonObject, id) + call.respond(file) } + delete { + val data = call.receive() - call.respond(res.status) + val path = pathPageIdMap.entries.find { it.value == call.parameters["id"]?.toIntOrNull() }?.key ?: return@delete call.respond(HttpStatusCode.NotFound, "Page not found") + val branch = call.request.queryParameters["branch"] ?: "master" + + @Serializable + data class DeleteGiteaPageRequest(val sha: String, val message: String, val branch: String, val author: Identity) + + val res = client.delete("repos/SteamWar/Website/contents/$path") { + contentType(ContentType.Application.Json) + setBody(DeleteGiteaPageRequest(data.sha, data.message, branch, Identity(call.principal()!!.user.userName, "admin-tool@steamwar.de"))) + } + + call.respond(res.status) + } + put { + @Serializable + data class UpdateGiteaPageRequest(val content: String, val sha: String, val message: String, val branch: String, val author: Identity) + + val data = call.receive() + val path = pathPageIdMap.entries.find { it.value == call.parameters["id"]?.toIntOrNull() }?.key ?: return@put call.respond(HttpStatusCode.NotFound, "Page not found") + + val res = client.put("repos/SteamWar/Website/contents/$path") { + contentType(ContentType.Application.Json) + setBody(UpdateGiteaPageRequest(data.content, data.sha, data.message, (call.request.queryParameters["branch"] ?: "master"), Identity(call.principal()!!.user.userName, "admin-tool@steamwar.de"))) + } + + call.respond(res.status) + } } + route("images") { + get { + val branch = call.request.queryParameters["branch"] ?: "master" - put("{id}") { - @Serializable - data class UpdateGiteaPageRequest(val content: String, val sha: String, val message: String, val branch: String, val author: Identity) - - val data = call.receive() - val path = pathPageIdMap.entries.find { it.value == call.parameters["id"]?.toIntOrNull() }?.key ?: return@put call.respond(HttpStatusCode.NotFound, "Page not found") - - val res = client.put("repos/SteamWar/Website/contents/$path") { - contentType(ContentType.Application.Json) - setBody(UpdateGiteaPageRequest(data.content, data.sha, data.message, (call.request.queryParameters["branch"] ?: "master"), Identity(call.principal()!!.user.userName, "admin-tool@steamwar.de"))) + call.respond(filesInDirectory("/src/images", branch)) } - - call.respond(res.status) } } } \ No newline at end of file From 527bc39d3848b032818b82afadae52190a1b5459 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 29 May 2025 08:44:58 +0200 Subject: [PATCH 020/153] Add some more CustomModelData ids to items --- BauSystem/build.gradle.kts | 1 + .../commands/schematiccommand/GUI.java | 4 ++-- .../de/steamwar/inventory/SchematicSelector.java | 16 ++++++++-------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/BauSystem/build.gradle.kts b/BauSystem/build.gradle.kts index fd9dca117..ebb9422dd 100644 --- a/BauSystem/build.gradle.kts +++ b/BauSystem/build.gradle.kts @@ -40,6 +40,7 @@ tasks.register("DevBau20") { description = "Run a 1.20 Dev Bau" dependsOn(":SpigotCore:shadowJar") dependsOn(":BauSystem:shadowJar") + dependsOn(":SchematicSystem:shadowJar") template = "Bau20" } diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java index cd953ed72..76cab2904 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java @@ -101,9 +101,9 @@ public class GUI { }); } - inv.setItem(9, SWItem.getMaterial("LEASH"), SchematicSystem.MESSAGE.parse("GUI_INFO_BACK", player), clickType -> { + inv.setItem(9, new SWItem(SWItem.getMaterial("LEASH"), SchematicSystem.MESSAGE.parse("GUI_INFO_BACK", player), clickType -> { back.reOpen(); - }); + }).setCustomModelData(2)); if(node.getOwner() == user.getId()){ if(!node.isDir() && node.getSchemtype().writeable()){ diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java index b6fe5c141..492dea073 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java @@ -124,15 +124,15 @@ public class SchematicSelector { SWListInv inv = new SWListInv<>(player, MessageFormat.format(injectable.createTitle(player), target.target.getName(player), (filter == null || filter.getName() == null)?(parent == null?"/":parent.generateBreadcrumbs()):filter.getName()), false, list, (clickType, node) -> handleClick(node, parent)); if(publicMode == PublicMode.ALL) { if(user.getId() == 0) { - inv.setItem(48, Material.BUCKET, Core.MESSAGE.parse("SCHEM_SELECTOR_OWN", player), clickType -> { + inv.setItem(48, new SWItem(Material.BUCKET, Core.MESSAGE.parse("SCHEM_SELECTOR_OWN", player), clickType -> { this.user = SteamwarUser.get(player.getUniqueId()); openList(null); - }); + }).setCustomModelData(1)); } else { - inv.setItem(48, Material.GLASS, Core.MESSAGE.parse("SCHEM_SELECTOR_PUB", player), clickType -> { + inv.setItem(48, new SWItem(Material.GLASS, Core.MESSAGE.parse("SCHEM_SELECTOR_PUB", player), clickType -> { this.user = SteamwarUser.get(0); openList(null); - }); + }).setCustomModelData(1)); } } if(target.target.dirs) { @@ -142,10 +142,10 @@ public class SchematicSelector { }); } if(user.getId() != 0) { - inv.setItem(50, Material.CHEST, Core.MESSAGE.parse("SCHEM_SELECTOR_NEW_DIR", player), clickType -> createFolderIn(parent)); + inv.setItem(50, new SWItem(Material.CHEST, Core.MESSAGE.parse("SCHEM_SELECTOR_NEW_DIR", player), clickType -> createFolderIn(parent)).setCustomModelData(2)); } - inv.setItem(51, Material.NAME_TAG, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER", player), clickType -> openFilter()); - inv.setItem(47, sorting.mat, Core.MESSAGE.parse("SCHEM_SELECTOR_SORTING", player), Arrays.asList( + inv.setItem(51, new SWItem(Material.NAME_TAG, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER", player), clickType -> openFilter()).setCustomModelData(3)); + inv.setItem(47, new SWItem(sorting.mat, Core.MESSAGE.parse("SCHEM_SELECTOR_SORTING", player), Arrays.asList( Core.MESSAGE.parse("SCHEM_SELECTOR_SORTING_CURRENT", player, sorting.parseName(player)), Core.MESSAGE.parse("SCHEM_SELECTOR_SORTING_DIRECTION", player, Core.MESSAGE.parse(invertSorting?"SCHEM_SELECTOR_SORTING_DSC":"SCHEM_SELECTOR_SORTING_ASC", player)) ), invertSorting, click -> { @@ -155,7 +155,7 @@ public class SchematicSelector { invertSorting = !invertSorting; } openList(parent); - }); + }).setCustomModelData(invertSorting ? 4 : 3)); injectable.onListRender(this, inv, parent); inv.open(); From 2f93f336c9df7da583569bd03180763cf3b47702 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 29 May 2025 14:30:06 +0200 Subject: [PATCH 021/153] Add image upload functionality and enhance page metadata creation. --- WebsiteBackend/src/de/steamwar/routes/Page.kt | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/WebsiteBackend/src/de/steamwar/routes/Page.kt b/WebsiteBackend/src/de/steamwar/routes/Page.kt index 139814c75..083d8dc4f 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Page.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Page.kt @@ -38,7 +38,11 @@ import io.ktor.server.response.* import io.ktor.server.routing.* import kotlinx.serialization.Serializable import kotlinx.serialization.json.* +import java.time.Instant +import java.time.LocalDate +import java.time.format.DateTimeFormatter import java.util.Base64 +import java.util.Date val pathPageIdMap = mutableMapOf() var pageId = 1 @@ -87,6 +91,9 @@ data class PageResponse( @Serializable data class CreatePageRequest(val path: String, val slug: String?, val title: String?) +@Serializable +data class AddImageRequest(val name: String, val data: String) + @Serializable data class CreateBranchRequest(val branch: String) @@ -99,6 +106,9 @@ data class MergeBranchRequest(val branch: String, val message: String) @Serializable data class DeletePageRequest(val sha: String, val message: String) +@Serializable +data class CreateGiteaPageRequest(val message: String, val content: String, val branch: String, val author: Identity) + fun Route.configurePage() { val client = HttpClient(Java) { install(ContentNegotiation) { @@ -148,8 +158,6 @@ fun Route.configurePage() { }) } post { - @Serializable - data class CreateGiteaPageRequest(val message: String, val content: String, val branch: String, val author: Identity) val req = call.receive() if(req.path.startsWith("src/content/")) { @@ -164,7 +172,10 @@ fun Route.configurePage() { --- title: ${req.title ?: "[Enter Title]"} description: [Enter Description] - slug: ${req.slug ?: "[Enter Slug]"} + key: ${req.slug ?: "[Enter Slug]"} + created: ${LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE)} + tags: + - test --- # ${req.path} @@ -259,6 +270,21 @@ fun Route.configurePage() { call.respond(filesInDirectory("/src/images", branch)) } + post { + val req = call.receive() + + client.post("repos/SteamWar/Website/contents/src/images/${req.name}") { + contentType(ContentType.Application.Json) + setBody(CreateGiteaPageRequest( + "Add Image ${req.name}", + req.data, + call.request.queryParameters["branch"] ?: "master", + Identity(call.principal()!!.user.userName, "admin-tool@steamwar.de" + ))) + } + + call.respond(HttpStatusCode.Created) + } } } } \ No newline at end of file From 7a9740c4c4f60f6c8a34b773bb856ca9877c6505 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 29 May 2025 15:05:01 +0200 Subject: [PATCH 022/153] Fix EventFight activeFights query and add null check for spectatePort in CookieEvents --- CommonCore/SQL/src/de/steamwar/sql/EventFight.java | 2 +- .../src/de/steamwar/velocitycore/listeners/CookieEvents.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/EventFight.java b/CommonCore/SQL/src/de/steamwar/sql/EventFight.java index 29b0620a6..9aa575107 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/EventFight.java +++ b/CommonCore/SQL/src/de/steamwar/sql/EventFight.java @@ -39,7 +39,7 @@ public class EventFight implements Comparable { private static final SelectStatement byId = table.select(Table.PRIMARY); private static final SelectStatement allComing = new SelectStatement<>(table, "SELECT * FROM EventFight WHERE StartTime > now() ORDER BY StartTime ASC"); private static final SelectStatement event = new SelectStatement<>(table, "SELECT * FROM EventFight WHERE EventID = ? ORDER BY StartTime ASC"); - private static final SelectStatement activeFights = new SelectStatement<>(table, "SELECT * FROM EventFight WHERE Fight IS NOT NULL AND StartTime > now() AND DATEDIFF(StartTime, now()) < 0"); + private static final SelectStatement activeFights = new SelectStatement<>(table, "SELECT * FROM EventFight WHERE Fight IS NOT NULL AND StartTime < now() AND DATEDIFF(StartTime, now()) < 0"); private static final Statement reschedule = table.update(Table.PRIMARY, "StartTime"); private static final Statement setResult = table.update(Table.PRIMARY, "Ergebnis"); private static final Statement setFight = table.update(Table.PRIMARY, "Fight"); diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/CookieEvents.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/CookieEvents.java index 2c319b723..4fb59b62b 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/CookieEvents.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/CookieEvents.java @@ -37,6 +37,7 @@ public class CookieEvents extends BasicListener { EventFight.getActiveFights().stream() .filter(fight -> fight.getTeamRed() == user.getTeam() || fight.getTeamBlue() == user.getTeam()) + .filter(fight -> fight.getSpectatePort() != null) .filter(fight -> fight.getSpectatePort() != 0) .findFirst() .flatMap(fight -> VelocityCore.getProxy().getServer(EventStarter.getSpectatePorts().get(fight.getSpectatePort()))) From 37f6723542e8a36b03a695d2952a54392c862ef3 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 29 May 2025 17:12:32 +0200 Subject: [PATCH 023/153] Add CommonCore.DATA and CMDs --- .../features/gui/editor/BauGuiEditor.java | 3 +- .../elements/LoaderInteractionElement.java | 5 +-- .../loader/elements/impl/LoaderWait.java | 3 +- .../simulator/gui/SimulatorGroupGui.java | 3 +- .../gui/SimulatorGroupSettingsGui.java | 3 +- .../simulator/gui/SimulatorMaterialGui.java | 3 +- .../simulator/gui/SimulatorObserverGui.java | 3 +- .../SimulatorObserverPhaseSettingsGui.java | 3 +- .../gui/SimulatorObserverSettingsGui.java | 3 +- .../simulator/gui/SimulatorRedstoneGui.java | 3 +- .../SimulatorRedstonePhaseSettingsGui.java | 3 +- .../gui/SimulatorRedstoneSettingsGui.java | 3 +- .../simulator/gui/SimulatorSettingsGui.java | 3 +- .../simulator/gui/SimulatorTNTGui.java | 3 +- .../gui/SimulatorTNTPhaseSettingsGui.java | 3 +- .../gui/SimulatorTNTSettingsGui.java | 3 +- .../slaves/laufbau/LaufbauSettings.java | 3 +- .../features/util/MaterialCommand.java | 3 +- CommonCore/Data/build.gradle.kts | 25 +++++++++++++ .../Data/src/de/steamwar/data/CMDs.java | 36 +++++++++++++++++++ CommonCore/build.gradle.kts | 1 + .../steamwar/inventory/SchematicSelector.java | 3 +- .../teamserver/command/MaterialCommand.java | 3 +- settings.gradle.kts | 1 + 24 files changed, 104 insertions(+), 21 deletions(-) create mode 100644 CommonCore/Data/build.gradle.kts create mode 100644 CommonCore/Data/src/de/steamwar/data/CMDs.java diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/gui/editor/BauGuiEditor.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/gui/editor/BauGuiEditor.java index acb3377a9..b548b60e4 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/gui/editor/BauGuiEditor.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/gui/editor/BauGuiEditor.java @@ -23,6 +23,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.gui.BauGUI; import de.steamwar.bausystem.linkage.specific.BauGuiItem; import de.steamwar.core.TrickyTrialsWrapper; +import de.steamwar.data.CMDs; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import de.steamwar.linkage.Linked; @@ -74,7 +75,7 @@ public class BauGuiEditor implements Listener { inv.setItem(mapping.getSize() + 5, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("GUI_EDITOR_ITEM_TRASH", p), Arrays.asList(BauSystem.MESSAGE.parse("GUI_EDITOR_ITEM_TRASH_LORE", p)), false, clickType -> { }).getItemStack()); inv.setItem(mapping.getSize() + 6, new SWItem(TrickyTrialsWrapper.impl.getTurtleScute(), BauSystem.MESSAGE.parse("GUI_EDITOR_ITEM_MORE", p)).getItemStack()); - inv.setItem(mapping.getSize() + 8, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("GUI_EDITOR_ITEM_CLOSE", p)).setCustomModelData(1).getItemStack()); + inv.setItem(mapping.getSize() + 8, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("GUI_EDITOR_ITEM_CLOSE", p)).setCustomModelData(CMDs.BACK).getItemStack()); p.openInventory(inv); p.getOpenInventory().setCursor(cursor == null ? new SWItem().getItemStack() : cursor); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderInteractionElement.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderInteractionElement.java index 25288955b..2caacbc44 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderInteractionElement.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderInteractionElement.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.loader.elements; import de.steamwar.bausystem.BauSystem; +import de.steamwar.data.CMDs; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; @@ -113,7 +114,7 @@ public abstract class LoaderInteractionElement & LoaderSetting }); listInv.setItem(48, new SWItem(Material.ARROW, "§7Back", clickType -> { backAction.run(); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.BACK)); listInv.setItem(50, new SWItem(Material.GHAST_SPAWN_EGG, "§7Insert another Setting", clickType -> { elements.add(defaultSetting); extraPower.add(0); @@ -150,7 +151,7 @@ public abstract class LoaderInteractionElement & LoaderSetting SWInventory swInventory = new SWInventory(player, guiSize, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_TITLE", player)); for (int i = guiSize - 9; i < guiSize; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7", clickType -> {})); - swInventory.setItem(guiSize - 9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).setCustomModelData(1).getItemStack(), clickType -> back.run()); + swInventory.setItem(guiSize - 9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).setCustomModelData(CMDs.BACK).getItemStack(), clickType -> back.run()); swInventory.setItem(guiSize - 5, new SWItem(Material.WOODEN_AXE, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_COPY", player)).getItemStack(), clickType -> { SWAnvilInv swAnvilInv = new SWAnvilInv(player, BauSystem.MESSAGE.parse("LOADER_GUI_COPY_TITLE", player), "1"); swAnvilInv.setCallback(s -> { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderWait.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderWait.java index 394963b13..618be7688 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderWait.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderWait.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.loader.elements.impl; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loader.elements.LoaderElement; +import de.steamwar.data.CMDs; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; @@ -60,7 +61,7 @@ public class LoaderWait implements LoaderElement { public void click(Player player, Runnable backAction) { SWInventory swInventory = new SWInventory(player, 18, BauSystem.MESSAGE.parse("LOADER_GUI_WAIT_TITLE", player)); for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); - swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_WAIT_BACK", player)).setCustomModelData(1).getItemStack(), clickType -> backAction.run()); + swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_WAIT_BACK", player)).setCustomModelData(CMDs.BACK).getItemStack(), clickType -> backAction.run()); swInventory.setItem(3, new SWItem(SWItem.getDye(1), BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_REMOVE_ONE", player), Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_REMOVE_ONE_SHIFT", player)), false, clickType -> {}).getItemStack(), clickType -> { delay -= clickType.isShiftClick() ? 5 : 1; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java index 185a22cac..c48681f59 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java @@ -25,6 +25,7 @@ import de.steamwar.bausystem.features.simulator.data.SimulatorElement; import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui; +import de.steamwar.data.CMDs; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -70,7 +71,7 @@ public class SimulatorGroupGui extends SimulatorPageGui> { inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.BACK)); inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { simulatorGroup.getElements().clear(); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java index e7617297b..a818755b2 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java @@ -25,6 +25,7 @@ import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; +import de.steamwar.data.CMDs; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -58,7 +59,7 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.BACK)); // Material Chooser inventory.setItem(4, simulatorGroup.toItem(player, clickType -> { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorMaterialGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorMaterialGui.java index 8d57b830c..5d509a99b 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorMaterialGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorMaterialGui.java @@ -23,6 +23,7 @@ import de.steamwar.bausystem.features.simulator.SimulatorWatcher; import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui; +import de.steamwar.data.CMDs; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -75,7 +76,7 @@ public class SimulatorMaterialGui extends SimulatorPageGui { })); inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.BACK)); } @Override diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverGui.java index dedcc69ea..836831f83 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverGui.java @@ -26,6 +26,7 @@ import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement; import de.steamwar.bausystem.features.simulator.data.observer.ObserverPhase; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorScrollGui; +import de.steamwar.data.CMDs; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -82,7 +83,7 @@ public class SimulatorObserverGui extends SimulatorScrollGui { new SimulatorGroupGui(player, simulator, newParent, simulatorGui).open(); } } - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.BACK)); inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { observer.getPhases().clear(); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverPhaseSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverPhaseSettingsGui.java index 0653ef987..9185f00ff 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverPhaseSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverPhaseSettingsGui.java @@ -27,6 +27,7 @@ import de.steamwar.bausystem.features.simulator.data.observer.ObserverPhase; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.core.Core; +import de.steamwar.data.CMDs; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.block.BlockFace; @@ -62,7 +63,7 @@ public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui { // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.BACK)); // Material Chooser inventory.setItem(4, observerElement.toItem(player, clickType -> { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverSettingsGui.java index 302245b3e..40c722d1a 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverSettingsGui.java @@ -24,6 +24,7 @@ import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; +import de.steamwar.data.CMDs; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -56,7 +57,7 @@ public class SimulatorObserverSettingsGui extends SimulatorBaseGui { // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.BACK)); // Material Chooser inventory.setItem(4, observer.toItem(player, clickType -> { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java index 9764621a8..3865be1f1 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java @@ -26,6 +26,7 @@ import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement; import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorScrollGui; +import de.steamwar.data.CMDs; import de.steamwar.inventory.SWItem; import lombok.AllArgsConstructor; import org.bukkit.Material; @@ -88,7 +89,7 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { redstone.getPhases().clear(); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java index 29ae1525b..6a5730999 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java @@ -27,6 +27,7 @@ import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.core.Core; +import de.steamwar.data.CMDs; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -60,7 +61,7 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.BACK)); // Material Chooser inventory.setItem(4, redstoneElement.toItem(player, clickType -> { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneSettingsGui.java index f8e6b3b83..f1eab5bbe 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneSettingsGui.java @@ -24,6 +24,7 @@ import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; +import de.steamwar.data.CMDs; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -55,7 +56,7 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.BACK)); // Material Chooser inventory.setItem(4, redstone.toItem(player, clickType -> { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java index 48b357256..a65ccba02 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.simulator.gui; import de.steamwar.bausystem.features.simulator.SimulatorWatcher; import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; +import de.steamwar.data.CMDs; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -47,7 +48,7 @@ public class SimulatorSettingsGui extends SimulatorBaseGui { // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.BACK)); // Material Chooser inventory.setItem(4, simulator.toItem(player, clickType -> { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java index a9b660d53..c643d31cd 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java @@ -29,6 +29,7 @@ import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorScrollGui; import de.steamwar.bausystem.region.Region; +import de.steamwar.data.CMDs; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -81,7 +82,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui { new SimulatorGroupGui(player, simulator, newParent, simulatorGui).open(); } } - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.BACK)); inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { tnt.getPhases().clear(); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java index fd78d18ac..c8ff1f040 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java @@ -27,6 +27,7 @@ import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.core.Core; +import de.steamwar.data.CMDs; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -60,7 +61,7 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.BACK)); // Material Chooser inventory.setItem(4, tntElement.toItem(player, clickType -> { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java index cd24bddbc..d9386b75c 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java @@ -24,6 +24,7 @@ import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; +import de.steamwar.data.CMDs; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -58,7 +59,7 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.BACK)); // Material Chooser List lore = new ArrayList<>(); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauSettings.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauSettings.java index e9ff017f8..51c482abe 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauSettings.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauSettings.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.slaves.laufbau; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.shared.Pair; +import de.steamwar.data.CMDs; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import org.bukkit.Material; @@ -91,7 +92,7 @@ public class LaufbauSettings { }); inv.setItem(49, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_GUI_BACK", p), clickType -> { open(); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.BACK)); inv.open(); } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/MaterialCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/MaterialCommand.java index a5a152430..5993eeeca 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/MaterialCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/MaterialCommand.java @@ -26,6 +26,7 @@ import de.steamwar.bausystem.shared.EnumDisplay; import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; +import de.steamwar.data.CMDs; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; @@ -204,7 +205,7 @@ public class MaterialCommand extends SWCommand implements Listener { Search search = searchMap.get(p); swInventory.setItem(0, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("MATERIAL_BACK", p), clickType -> { materialGUI(p); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.BACK)); swInventory.setItem(10, new SWItem(Material.NAME_TAG, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_NAME", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.name), clickType -> { SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_NAME", p), search.name); swAnvilInv.setCallback(s -> { diff --git a/CommonCore/Data/build.gradle.kts b/CommonCore/Data/build.gradle.kts new file mode 100644 index 000000000..da326bfe1 --- /dev/null +++ b/CommonCore/Data/build.gradle.kts @@ -0,0 +1,25 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 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 . + */ + +plugins { + steamwar.java +} + +dependencies { +} \ No newline at end of file diff --git a/CommonCore/Data/src/de/steamwar/data/CMDs.java b/CommonCore/Data/src/de/steamwar/data/CMDs.java new file mode 100644 index 000000000..a91086662 --- /dev/null +++ b/CommonCore/Data/src/de/steamwar/data/CMDs.java @@ -0,0 +1,36 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.data; + +// Custom Model Data Constants +public interface CMDs { + + // Material.ARROW + int BACK = 1; + + // Material.BARRIER + int SIMULATOR_DELETE = 1; + + // Material.REPEATER + int SIMULATOR_SETTINGS = 1; + + // Material.ENDER_PEARL and Material.ENDER_EYE + int SIMULATOR_ENABLED_OR_DISABLED = 1; +} diff --git a/CommonCore/build.gradle.kts b/CommonCore/build.gradle.kts index 91b10d6f5..8e2df2bc8 100644 --- a/CommonCore/build.gradle.kts +++ b/CommonCore/build.gradle.kts @@ -24,4 +24,5 @@ plugins { dependencies { api(project(":CommonCore:SQL")) api(project(":CommonCore:Network")) + api(project(":CommonCore:Data")) } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java index 492dea073..084e431a2 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java @@ -24,6 +24,7 @@ import com.google.gson.JsonObject; import com.google.gson.internal.Streams; import com.google.gson.stream.JsonReader; import de.steamwar.core.Core; +import de.steamwar.data.CMDs; import de.steamwar.sql.*; import lombok.*; import org.bukkit.Bukkit; @@ -113,7 +114,7 @@ public class SchematicSelector { List> list = new ArrayList<>(); if(depth != 0) { - list.add(new SWListInv.SWListEntry<>(new SWItem(Material.ARROW, Core.MESSAGE.parse("SCHEM_SELECTOR_BACK", player), clickType -> {}).setCustomModelData(1), null)); + list.add(new SWListInv.SWListEntry<>(new SWItem(Material.ARROW, Core.MESSAGE.parse("SCHEM_SELECTOR_BACK", player), clickType -> {}).setCustomModelData(CMDs.BACK), null)); } for (SchematicNode node : nodes) { diff --git a/Teamserver/src/de/steamwar/teamserver/command/MaterialCommand.java b/Teamserver/src/de/steamwar/teamserver/command/MaterialCommand.java index cea302789..808a54692 100644 --- a/Teamserver/src/de/steamwar/teamserver/command/MaterialCommand.java +++ b/Teamserver/src/de/steamwar/teamserver/command/MaterialCommand.java @@ -20,6 +20,7 @@ package de.steamwar.teamserver.command; import de.steamwar.command.SWCommand; +import de.steamwar.data.CMDs; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; @@ -208,7 +209,7 @@ public class MaterialCommand extends SWCommand implements Listener { Search search = searchMap.get(p); swInventory.setItem(0, new SWItem(Material.ARROW, Builder.MESSAGE.parse("MATERIAL_BACK", p), clickType -> { materialGUI(p); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.BACK)); swInventory.setItem(10, new SWItem(Material.NAME_TAG, Builder.MESSAGE.parse("MATERIAL_SEARCH_NAME", p) + Builder.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.name), clickType -> { SWAnvilInv swAnvilInv = new SWAnvilInv(p, Builder.MESSAGE.parse("MATERIAL_SEARCH_NAME", p), search.name); swAnvilInv.setCallback(s -> { diff --git a/settings.gradle.kts b/settings.gradle.kts index dc94bc0cc..98af9b7f4 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -184,6 +184,7 @@ include("CommandFramework") include( "CommonCore", + "CommonCore:Data", "CommonCore:SQL", "CommonCore:Network" ) From 7b059cde0e94fc2b857fce2b335cb0372c53002f Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 31 May 2025 08:51:56 +0200 Subject: [PATCH 024/153] Add customModelData to Velocity SWItem --- .../src/de/steamwar/inventory/SWItem.java | 3 +++ .../src/de/steamwar/velocitycore/inventory/SWItem.java | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWItem.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWItem.java index 2220c471f..b368332d5 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWItem.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWItem.java @@ -142,6 +142,9 @@ public class SWItem { loreArray.forEach(jsonElement -> lore.add(jsonElement.getAsString())); item.setLore(lore); } + + if (itemJson.has("customModelData")) + item.setCustomModelData(itemJson.get("customModelData").getAsInt()); return item; } diff --git a/VelocityCore/src/de/steamwar/velocitycore/inventory/SWItem.java b/VelocityCore/src/de/steamwar/velocitycore/inventory/SWItem.java index c2db126ff..ec3b6f40f 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/inventory/SWItem.java +++ b/VelocityCore/src/de/steamwar/velocitycore/inventory/SWItem.java @@ -42,6 +42,7 @@ public class SWItem { @Getter private InvCallback callback; private int color = 0; + private int customModelData = 0; public SWItem(String material, Message title) { this.material = material.toUpperCase(); @@ -64,6 +65,11 @@ public class SWItem { return this; } + public SWItem setCustomModelData(int customModelData) { + this.customModelData = customModelData; + return this; + } + public JsonObject writeToString(Chatter player, int position) { JsonObject object = new JsonObject(); object.addProperty("material", material); @@ -84,6 +90,9 @@ public class SWItem { } object.add("lore", array); } + if (customModelData > 0) { + object.addProperty("customModelData", customModelData); + } return object; } From 083c5c07c2872a5544272ce1082b2cb2ab542d78 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 31 May 2025 09:39:03 +0200 Subject: [PATCH 025/153] Update CMDs for all current CustomModelData usages --- .../simulator/gui/SimulatorGroupGui.java | 6 +-- .../gui/SimulatorGroupSettingsGui.java | 17 ++++--- .../features/simulator/gui/SimulatorGui.java | 3 +- .../simulator/gui/SimulatorObserverGui.java | 20 ++++---- .../SimulatorObserverPhaseSettingsGui.java | 10 ++-- .../gui/SimulatorObserverSettingsGui.java | 16 +++---- .../simulator/gui/SimulatorRedstoneGui.java | 20 ++++---- .../SimulatorRedstonePhaseSettingsGui.java | 14 +++--- .../gui/SimulatorRedstoneSettingsGui.java | 16 +++---- .../simulator/gui/SimulatorSettingsGui.java | 12 ++--- .../simulator/gui/SimulatorTNTGui.java | 24 +++++----- .../gui/SimulatorTNTPhaseSettingsGui.java | 18 +++---- .../gui/SimulatorTNTSettingsGui.java | 16 +++---- .../simulator/gui/base/SimulatorPageGui.java | 5 +- .../gui/base/SimulatorScrollGui.java | 5 +- .../Data/src/de/steamwar/data/CMDs.java | 48 +++++++++++++++++++ .../commands/schematiccommand/GUI.java | 6 +-- .../src/de/steamwar/inventory/SWListInv.java | 13 ++--- .../steamwar/inventory/SchematicSelector.java | 10 ++-- 19 files changed, 165 insertions(+), 114 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java index c48681f59..6483aea44 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java @@ -76,7 +76,7 @@ public class SimulatorGroupGui extends SimulatorPageGui> { inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { simulatorGroup.getElements().clear(); SimulatorWatcher.update(simulator); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.SIMULATOR_DELETE)); inventory.setItem(4, simulatorGroup.toItem(player, clickType -> { if (simulatorGroup.getMaterial() == null) return; @@ -86,7 +86,7 @@ public class SimulatorGroupGui extends SimulatorPageGui> { inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> { new SimulatorGroupSettingsGui(player, simulator, simulatorGroup, this).open(); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.SIMULATOR_SETTINGS)); boolean disabled = simulatorGroup.getMaterial() == null ? simulatorGroup.getElements().stream().allMatch(SimulatorElement::isDisabled) : simulatorGroup.isDisabled(); inventory.setItem(50, new SWItem(disabled ? Material.ENDER_PEARL : Material.ENDER_EYE, simulatorGroup.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { if (simulatorGroup.getMaterial() == null) { @@ -97,7 +97,7 @@ public class SimulatorGroupGui extends SimulatorPageGui> { simulatorGroup.setDisabled(!disabled); } SimulatorWatcher.update(simulator); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.SIMULATOR_ENABLED_OR_DISABLED)); } @Override diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java index a818755b2..705a76f0a 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java @@ -29,7 +29,6 @@ import de.steamwar.data.CMDs; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; -import org.bukkit.util.Vector; import java.util.Arrays; @@ -73,7 +72,7 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { simulatorGroup.changeBaseTicks(clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> { new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> { if (integer < 0) return false; @@ -91,7 +90,7 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { simulatorGroup.changeBaseTicks(clickType.isShiftClick() ? -5 : -1); } SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); boolean allTNT = simulatorGroup.getElements().stream().allMatch(TNTElement.class::isInstance); @@ -167,7 +166,7 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> { simulatorGroup.move(clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1, 0, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); inventory.setItem(24, new SWItem(Material.PAPER, "§eX", clickType -> { new SimulatorAnvilGui<>(player, "Relative X", "", Double::parseDouble, number -> { if(!allTNT){ @@ -181,13 +180,13 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { simulatorGroup.move(clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); //Pos Y inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> { simulatorGroup.move(0, clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); inventory.setItem(25, new SWItem(Material.PAPER, "§eY", clickType -> { new SimulatorAnvilGui<>(player, "Relative Y", "", Double::parseDouble, number -> { if(!allTNT){ @@ -201,13 +200,13 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { simulatorGroup.move(0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_ENABLED_OR_DISABLED)); //Pos Z inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> { simulatorGroup.move(0, 0, clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); inventory.setItem(26, new SWItem(Material.PAPER, "§eZ", clickType -> { new SimulatorAnvilGui<>(player, "Relative Z", "", Double::parseDouble, number -> { if(!allTNT){ @@ -221,6 +220,6 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { simulatorGroup.move(0, 0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGui.java index e165b851d..55cc43767 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGui.java @@ -24,6 +24,7 @@ import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.SimulatorElement; import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui; +import de.steamwar.data.CMDs; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -50,7 +51,7 @@ public class SimulatorGui extends SimulatorPageGui { })); inventory.setItem(49, new SWItem(Material.REPEATER, "§eSettings", clickType -> { new SimulatorSettingsGui(player, simulator, this).open(); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.SIMULATOR_SETTINGS)); } @Override diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverGui.java index 836831f83..81b3869bb 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverGui.java @@ -88,7 +88,7 @@ public class SimulatorObserverGui extends SimulatorScrollGui { inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { observer.getPhases().clear(); SimulatorWatcher.update(simulator); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.SIMULATOR_DELETE)); // Material Chooser inventory.setItem(4, observer.toItem(player, clickType -> { @@ -98,18 +98,18 @@ public class SimulatorObserverGui extends SimulatorScrollGui { // Settings inventory.setItem(47, new SWItem(Material.REPEATER, "§eSettings", clickType -> { new SimulatorObserverSettingsGui(player, simulator, observer, this).open(); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.SIMULATOR_SETTINGS)); // Enable/Disable inventory.setItem(48, new SWItem(observer.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, observer.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { observer.setDisabled(!observer.isDisabled()); SimulatorWatcher.update(simulator); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.SIMULATOR_ENABLED_OR_DISABLED)); // Group chooser inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> { new SimulatorGroupChooserGui(player, simulator, observer, observer.getGroup(simulator), this).open(); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.SIMULATOR_JOIN_GROUP)); } @Override @@ -152,15 +152,15 @@ public class SimulatorObserverGui extends SimulatorScrollGui { new SWItem(SWItem.getDye(getter.get() < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { setter.accept(Math.min(max, getter.get() + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(3), + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED), observer, new SWItem(SWItem.getDye(getter.get() > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> { setter.accept(Math.max(min, getter.get() - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(3), + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED), new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> { new SimulatorObserverPhaseSettingsGui(player, simulator, this.observer, observerPhase, this).open(); - }).setCustomModelData(1), + }).setCustomModelData(CMDs.SIMULATOR_EDIT_ACTIVATION), }; } @@ -169,12 +169,12 @@ public class SimulatorObserverGui extends SimulatorScrollGui { return new SWItem[]{ new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { addNewPhase(clickType.isShiftClick()); - }).setCustomModelData(3), + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED), new SWItem(Material.QUARTZ, "§eObserver§8:§a New Phase", clickType -> { addNewPhase(false); - }).setCustomModelData(1), + }).setCustomModelData(CMDs.SIMULATOR_NEW_PHASE), new SWItem(SWItem.getDye(8), "§7", clickType -> { - }).setCustomModelData(3), + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED), }; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverPhaseSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverPhaseSettingsGui.java index 9185f00ff..dec581215 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverPhaseSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverPhaseSettingsGui.java @@ -75,7 +75,7 @@ public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui { observerElement.getPhases().remove(observer); back.open(); SimulatorWatcher.update(simulator); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.SIMULATOR_DELETE)); int index = observerElement.getPhases().indexOf(observer); int min; @@ -99,7 +99,7 @@ public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(10, new SWItem(SWItem.getDye(offset < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { observer.setTickOffset(Math.min(max, offset + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> { new SimulatorAnvilGui<>(player, "Start at", offset + "", Integer::parseInt, integer -> { @@ -115,14 +115,14 @@ public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(28, new SWItem(SWItem.getDye(offset > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { observer.setTickOffset(Math.max(min, offset - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); //Order int order = observer.getOrder(); inventory.setItem(13, new SWItem(SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { observer.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR"); SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eActivation Order§8:§7 " + order, clickType -> { @@ -140,7 +140,7 @@ public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(31, new SWItem(SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { observer.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); // Update orientation inventory.setItem(25, new SWItem(Material.SUNFLOWER, "§7", clickType -> { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverSettingsGui.java index 40c722d1a..71d9448e7 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverSettingsGui.java @@ -69,7 +69,7 @@ public class SimulatorObserverSettingsGui extends SimulatorBaseGui { inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { observer.changeBaseTicks(clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> { new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> { if (integer < 0) return false; @@ -87,13 +87,13 @@ public class SimulatorObserverSettingsGui extends SimulatorBaseGui { observer.changeBaseTicks(clickType.isShiftClick() ? -5 : -1); } SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); //Pos X inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { observer.move(clickType.isShiftClick() ? 5 : 1, 0, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + observer.getPosition().getBlockX(), clickType -> { new SimulatorAnvilGui<>(player, "X", observer.getPosition().getBlockX() + "", Integer::parseInt, i -> { observer.getPosition().setX(i); @@ -104,13 +104,13 @@ public class SimulatorObserverSettingsGui extends SimulatorBaseGui { inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { observer.move(clickType.isShiftClick() ? -5 : -1, 0, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); //Pos Y inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { observer.move(0, clickType.isShiftClick() ? 5 : 1, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_ENABLED_OR_DISABLED)); inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + observer.getPosition().getBlockY(), clickType -> { new SimulatorAnvilGui<>(player, "Y", observer.getPosition().getBlockY() + "", Integer::parseInt, i -> { observer.getPosition().setY(i); @@ -121,13 +121,13 @@ public class SimulatorObserverSettingsGui extends SimulatorBaseGui { inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { observer.move(0, clickType.isShiftClick() ? -5 : -1, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); //Pos Z inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { observer.move(0, 0, clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_ENABLED_OR_DISABLED)); inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + observer.getPosition().getBlockZ(), clickType -> { new SimulatorAnvilGui<>(player, "Z", observer.getPosition().getBlockZ() + "", Integer::parseInt, i -> { observer.getPosition().setZ(i); @@ -138,6 +138,6 @@ public class SimulatorObserverSettingsGui extends SimulatorBaseGui { inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { observer.move(0, 0, clickType.isShiftClick() ? -5 : -1); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java index 3865be1f1..c0809cfda 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java @@ -94,7 +94,7 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { redstone.getPhases().clear(); SimulatorWatcher.update(simulator); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.SIMULATOR_DELETE)); // Material Chooser inventory.setItem(4, redstone.toItem(player, clickType -> { @@ -104,18 +104,18 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { new SimulatorRedstoneSettingsGui(player, simulator, redstone, this).open(); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.SIMULATOR_SETTINGS)); // Enable/Disable inventory.setItem(48, new SWItem(redstone.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, redstone.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { redstone.setDisabled(!redstone.isDisabled()); SimulatorWatcher.update(simulator); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.SIMULATOR_ENABLED_OR_DISABLED)); // Group chooser inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> { new SimulatorGroupChooserGui(player, simulator, redstone, redstone.getGroup(simulator), this).open(); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.SIMULATOR_JOIN_GROUP)); } @Override @@ -167,15 +167,15 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { setter.accept(Math.min(max, getter.get() + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(3), + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED), redstone, new SWItem(SWItem.getDye(getter.get() > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> { setter.accept(Math.max(min, getter.get() - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(3), + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED), new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> { new SimulatorRedstonePhaseSettingsGui(player, simulator, this.redstone, redstoneSubPhase.phase, this).open(); - }).setCustomModelData(1), + }).setCustomModelData(CMDs.SIMULATOR_EDIT_ACTIVATION), }; } @@ -184,12 +184,12 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { addNewPhase(clickType.isShiftClick()); - }).setCustomModelData(3), + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED), new SWItem(Material.REDSTONE, "§eRedstone§8:§a New Phase", clickType -> { addNewPhase(false); - }).setCustomModelData(1), + }).setCustomModelData(CMDs.SIMULATOR_NEW_PHASE), new SWItem(SWItem.getDye(8), "§7", clickType -> { - }).setCustomModelData(3), + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED), }; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java index 6a5730999..dd957d354 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java @@ -73,7 +73,7 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { redstoneElement.getPhases().remove(redstone); back.open(); SimulatorWatcher.update(simulator); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.SIMULATOR_DELETE)); int index = redstoneElement.getPhases().indexOf(redstone); int min; @@ -100,7 +100,7 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(10, new SWItem(SWItem.getDye(offset < maxOffset ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.setTickOffset(Math.min(maxOffset, offset + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> { new SimulatorAnvilGui<>(player, "Start at", offset + "", Integer::parseInt, integer -> { @@ -116,14 +116,14 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(28, new SWItem(SWItem.getDye(offset > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.setTickOffset(Math.max(min, offset - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); //Lifetime int lifetime = redstone.getLifetime(); inventory.setItem(11, new SWItem(SWItem.getDye(lifetime < maxLifetime ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.setLifetime(Math.min(maxLifetime, lifetime + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eActivation Time§8:§7 " + lifetime, clickType -> { new SimulatorAnvilGui<>(player, "Activation Time", lifetime + "", Integer::parseInt, integer -> { @@ -139,14 +139,14 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(29, new SWItem(SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.setLifetime(Math.max(0, lifetime - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); //Order int order = redstone.getOrder(); inventory.setItem(13, new SWItem(SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR"); SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eActivation Order§8:§7 " + order, clickType -> { @@ -164,6 +164,6 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(31, new SWItem(SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneSettingsGui.java index f1eab5bbe..4b1f6ed36 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneSettingsGui.java @@ -68,7 +68,7 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.changeBaseTicks(clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> { new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> { if (integer < 0) return false; @@ -86,13 +86,13 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { redstone.changeBaseTicks(clickType.isShiftClick() ? -5 : -1); } SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); //Pos X inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.move(clickType.isShiftClick() ? 5 : 1, 0, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + redstone.getPosition().getBlockX(), clickType -> { new SimulatorAnvilGui<>(player, "X", redstone.getPosition().getBlockX() + "", Integer::parseInt, i -> { redstone.getPosition().setX(i); @@ -103,13 +103,13 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.move(clickType.isShiftClick() ? -5 : -1, 0, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); //Pos Y inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.move(0, clickType.isShiftClick() ? 5 : 1, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + redstone.getPosition().getBlockY(), clickType -> { new SimulatorAnvilGui<>(player, "Y", redstone.getPosition().getBlockY() + "", Integer::parseInt, i -> { redstone.getPosition().setY(i); @@ -120,13 +120,13 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.move(0, clickType.isShiftClick() ? -5 : -1, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); //Pos Z inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.move(0, 0, clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + redstone.getPosition().getBlockZ(), clickType -> { new SimulatorAnvilGui<>(player, "Z", redstone.getPosition().getBlockZ() + "", Integer::parseInt, i -> { redstone.getPosition().setZ(i); @@ -137,6 +137,6 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.move(0, 0, clickType.isShiftClick() ? -5 : -1); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java index a65ccba02..87ecb2249 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java @@ -65,36 +65,36 @@ public class SimulatorSettingsGui extends SimulatorBaseGui { inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { simulator.move(clickType.isShiftClick() ? 5 : 1, 0, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); inventory.setItem(24, new SWItem(Material.PAPER, "§eX", clickType -> { })); inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { simulator.move(clickType.isShiftClick() ? -5 : -1, 0, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); //Pos Y inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { simulator.move(0, clickType.isShiftClick() ? 5 : 1, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); inventory.setItem(25, new SWItem(Material.PAPER, "§eY", clickType -> { })); inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { simulator.move(0, clickType.isShiftClick() ? -5 : -1, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); //Pos Z inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { simulator.move(0, 0, clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); inventory.setItem(26, new SWItem(Material.PAPER, "§eZ", clickType -> { })); inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { simulator.move(0, 0, clickType.isShiftClick() ? -5 : -1); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java index c643d31cd..30fbe20c1 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java @@ -87,7 +87,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui { inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { tnt.getPhases().clear(); SimulatorWatcher.update(simulator); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.SIMULATOR_DELETE)); // Material Chooser inventory.setItem(4, tnt.toItem(player, clickType -> { @@ -96,11 +96,11 @@ public class SimulatorTNTGui extends SimulatorScrollGui { inventory.setItem(47, new SWItem(Material.REPEATER, "§eSettings", clickType -> { new SimulatorTNTSettingsGui(player, simulator, tnt, this).open(); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.SIMULATOR_SETTINGS)); inventory.setItem(48, new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { tnt.setDisabled(!tnt.isDisabled()); SimulatorWatcher.update(simulator); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.SIMULATOR_ENABLED_OR_DISABLED)); inventory.setItem(49, new SWItem(Material.CALIBRATED_SCULK_SENSOR, "§eCreate Stab", click -> { new SimulatorAnvilGui<>(player, "Depth Limit", "", Integer::parseInt, depthLimit -> { if (depthLimit <= 0) return false; @@ -108,17 +108,17 @@ public class SimulatorTNTGui extends SimulatorScrollGui { SimulatorWatcher.update(simulator); return true; }, null).open(); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.SIMULATOR_CREATE_STAB)); inventory.setItem(50, new SWItem(Material.CHEST, parent.getElements().size() == 1 ? "§eMake Group" : "§eAdd another TNT to Group", clickType -> { TNTElement tntElement = new TNTElement(tnt.getPosition().clone()); tntElement.add(new TNTPhase()); parent.add(tntElement); new SimulatorGroupGui(player, simulator, parent, new SimulatorGui(player, simulator)).open(); SimulatorWatcher.update(simulator); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.SIMULATOR_MAKE_GROUP)); inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> { new SimulatorGroupChooserGui(player, simulator, tnt, tnt.getGroup(simulator), this).open(); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.SIMULATOR_JOIN_GROUP)); } @Override @@ -137,15 +137,15 @@ public class SimulatorTNTGui extends SimulatorScrollGui { new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { tntSetting.setCount(tntSetting.getCount() + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); - }).setCustomModelData(3), + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED), tnt, new SWItem(SWItem.getDye(tntSetting.getCount() > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> { tntSetting.setCount(Math.max(1, tntSetting.getCount() - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(3), + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED), new SWItem(Material.ANVIL, "§eEdit Phase", clickType -> { new SimulatorTNTPhaseSettingsGui(player, simulator, this.tnt, tntSetting, this).open(); - }).setCustomModelData(1), + }).setCustomModelData(CMDs.SIMULATOR_EDIT_ACTIVATION), }; } @@ -154,12 +154,12 @@ public class SimulatorTNTGui extends SimulatorScrollGui { return new SWItem[]{ new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { addNewPhase(clickType.isShiftClick()); - }).setCustomModelData(3), + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED), new SWItem(Material.GUNPOWDER, "§eTNT§8:§a New Phase", clickType -> { addNewPhase(false); - }).setCustomModelData(1), + }).setCustomModelData(CMDs.SIMULATOR_NEW_PHASE), new SWItem(SWItem.getDye(8), "§7", clickType -> { - }).setCustomModelData(3), + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED), }; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java index c8ff1f040..25ca10dc5 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java @@ -73,14 +73,14 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { tntElement.getPhases().remove(tnt); back.open(); SimulatorWatcher.update(simulator); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.SIMULATOR_DELETE)); //Count int count = tnt.getCount(); inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { tnt.setCount(count + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); SWItem countItem = new SWItem(Material.TNT, "§eCount§8:§7 " + count, clickType -> { new SimulatorAnvilGui<>(player, "Count", count + "", Integer::parseInt, integer -> { @@ -96,14 +96,14 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(27, new SWItem(SWItem.getDye(count > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { tnt.setCount(Math.max(1, count - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); //Tick Offset int offset = tnt.getTickOffset(); inventory.setItem(10, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { tnt.setTickOffset(offset + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> { new SimulatorAnvilGui<>(player, "Start at", offset + "", Integer::parseInt, integer -> { @@ -119,14 +119,14 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(28, new SWItem(SWItem.getDye(offset > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { tnt.setTickOffset(Math.max(0, offset - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); //Lifetime int lifetime = tnt.getLifetime(); inventory.setItem(11, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { tnt.setLifetime(lifetime + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eLifetime§8:§7 " + lifetime, clickType -> { new SimulatorAnvilGui<>(player, "Lifetime", lifetime + "", Integer::parseInt, integer -> { @@ -142,14 +142,14 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(29, new SWItem(SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { tnt.setLifetime(Math.max(1, lifetime - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); //Order int order = tnt.getOrder(); inventory.setItem(13, new SWItem(SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { tnt.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR"); SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eCalculation Order§8:§7 " + order, clickType -> { @@ -167,7 +167,7 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(31, new SWItem(SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { tnt.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); //Jump SWItem jumpX = new SWItem(tnt.isXJump() ? Material.LIME_WOOL : Material.RED_WOOL, "§7TNT §eJump X§8: " + (tnt.isZJump() ? "§aon" : "§coff"), clickType -> { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java index d9386b75c..a897c96c3 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java @@ -78,7 +78,7 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { tnt.changeBaseTicks(clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> { new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> { if (integer < 0) return false; @@ -96,7 +96,7 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { tnt.changeBaseTicks(clickType.isShiftClick() ? -5 : -1); } SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); // Subpixel Alignment inventory.setItem(21, new SWItem(Material.SUNFLOWER, "§7Align§8: §eCenter", clickType -> { @@ -139,7 +139,7 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> { tnt.move(clickType.isShiftClick() ? 0.0625 : 1, 0, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + tnt.getPosition().getX(), clickType -> { new SimulatorAnvilGui<>(player, "X", tnt.getPosition().getX() + "", Double::parseDouble, d -> { tnt.getPosition().setX(d); @@ -150,13 +150,13 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { tnt.move(clickType.isShiftClick() ? -0.0625 : -1, 0, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); // Pos Y inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> { tnt.move(0, clickType.isShiftClick() ? 0.0625 : 1, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + tnt.getPosition().getY(), clickType -> { new SimulatorAnvilGui<>(player, "Y", tnt.getPosition().getY() + "", Double::parseDouble, d -> { tnt.getPosition().setY(d); @@ -167,13 +167,13 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { tnt.move(0, clickType.isShiftClick() ? -0.0625 : -1, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); // Pos Z inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> { tnt.move(0, 0, clickType.isShiftClick() ? 0.0625 : 1); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + tnt.getPosition().getZ(), clickType -> { new SimulatorAnvilGui<>(player, "Z", tnt.getPosition().getZ() + "", Double::parseDouble, d -> { tnt.getPosition().setZ(d); @@ -184,6 +184,6 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { tnt.move(0, 0, clickType.isShiftClick() ? -0.0625 : -1); SimulatorWatcher.update(simulator); - }).setCustomModelData(3)); + }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorPageGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorPageGui.java index d3f24b568..a6ff9f153 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorPageGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorPageGui.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.simulator.gui.base; import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.core.Core; +import de.steamwar.data.CMDs; import de.steamwar.inventory.SWItem; import org.bukkit.entity.Player; @@ -55,14 +56,14 @@ public abstract class SimulatorPageGui extends SimulatorBaseGui { page--; open(); } - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.PREVIOUS_PAGE)); boolean hasNext = page < maxPage() - (data.size() % (size - 18) == 0 ? 1 : 0); inventory.setItem(size - 1, new SWItem(SWItem.getDye(hasNext ? 10 : 8), hasNext ? (byte) 10 : (byte) 8, Core.MESSAGE.parse(hasNext ? "SWLISINV_NEXT_PAGE_ACTIVE" : "SWLISINV_NEXT_PAGE_INACTIVE", player), clickType -> { if (hasNext) { page++; open(); } - }).setCustomModelData(2)); + }).setCustomModelData(CMDs.NEXT_PAGE)); int minElement = page * (size - 18); int maxElement = Math.min(data.size(), (page + 1) * (size - 18)); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorScrollGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorScrollGui.java index 6538196a3..974f64edd 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorScrollGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorScrollGui.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.simulator.gui.base; import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.core.Core; +import de.steamwar.data.CMDs; import de.steamwar.inventory.SWItem; import org.bukkit.entity.Player; @@ -55,14 +56,14 @@ public abstract class SimulatorScrollGui extends SimulatorBaseGui { scroll = Math.max(0, scroll - 9); open(); } - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.PREVIOUS_PAGE)); boolean hasNext = (data.size() + 1) - scroll > 9; inventory.setItem(size - 1, new SWItem(SWItem.getDye(hasNext ? 10 : 8), hasNext ? (byte) 10 : (byte) 8, Core.MESSAGE.parse(hasNext ? "SWLISINV_NEXT_PAGE_ACTIVE" : "SWLISINV_NEXT_PAGE_INACTIVE", player), clickType -> { if (hasNext) { scroll = Math.min(scroll + 9, data.size() + 1 - 9); open(); } - }).setCustomModelData(2)); + }).setCustomModelData(CMDs.NEXT_PAGE)); for (int i = 0; i < 9; i++) { if (scroll + i < data.size()) { diff --git a/CommonCore/Data/src/de/steamwar/data/CMDs.java b/CommonCore/Data/src/de/steamwar/data/CMDs.java index a91086662..c790ea309 100644 --- a/CommonCore/Data/src/de/steamwar/data/CMDs.java +++ b/CommonCore/Data/src/de/steamwar/data/CMDs.java @@ -25,6 +25,12 @@ public interface CMDs { // Material.ARROW int BACK = 1; + // Material.DYE (Color 10/8) + int PREVIOUS_PAGE = 1; + + // Material.DYE (Color 10/8) + int NEXT_PAGE = 2; + // Material.BARRIER int SIMULATOR_DELETE = 1; @@ -33,4 +39,46 @@ public interface CMDs { // Material.ENDER_PEARL and Material.ENDER_EYE int SIMULATOR_ENABLED_OR_DISABLED = 1; + + // Material.DYE (Color 10/8) + int SIMULATOR_INCREMENT_OR_DISABLED = 3; + + // Material.DYE (Color 1/8) + int SIMULATOR_DECREMENT_OR_DISABLED = 3; + + // Material.LEAD + int SIMULATOR_JOIN_GROUP = 1; + + // Material.ANVIL + int SIMULATOR_EDIT_ACTIVATION = 1; + + // Material.QUARTZ, Material.REDSTONE, Material.GUNPOWDER + int SIMULATOR_NEW_PHASE = 1; + + // Material.CALIBRATED_SCULK_SENSOR + int SIMULATOR_CREATE_STAB = 1; + + // Material.CHEST + int SIMULATOR_MAKE_GROUP = 1; + + // Material.LEAD + int SCHEMATIC_GUI_BACK = 2; + + // Material.BUCKET + int SCHEMATIC_GUI_OWN = 1; + + // Material.GLASS + int SCHEMATIC_GUI_PUBLIC = 1; + + // Material.CHEST + int SCHEMATIC_GUI_NEW_DIR = 2; + + // Material.NAME_TAG + int SCHEMATIC_GUI_FILTER = 3; + + // Material.PAPER, Material.CAULDRON, Material.CLOCK + int SCHEMATIC_SORT_ASCENDING = 3; + + // Material.PAPER, Material.CAULDRON, Material.CLOCK + int SCHEMATIC_SORT_DESCENDING = 4; } diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java index 76cab2904..8a6cded6d 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java @@ -21,12 +21,12 @@ package de.steamwar.schematicsystem.commands.schematiccommand; import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.core.Core; +import de.steamwar.data.CMDs; import de.steamwar.inventory.*; import de.steamwar.schematicsystem.CheckSchemType; import de.steamwar.schematicsystem.SafeSchematicNode; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.schematicsystem.autocheck.AutoChecker; -import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils; import de.steamwar.sql.*; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -38,7 +38,7 @@ import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; -import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils.*; +import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils.getUser; public class GUI { private GUI() {} @@ -103,7 +103,7 @@ public class GUI { inv.setItem(9, new SWItem(SWItem.getMaterial("LEASH"), SchematicSystem.MESSAGE.parse("GUI_INFO_BACK", player), clickType -> { back.reOpen(); - }).setCustomModelData(2)); + }).setCustomModelData(CMDs.SCHEMATIC_GUI_BACK)); if(node.getOwner() == user.getId()){ if(!node.isDir() && node.getSchemtype().writeable()){ diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java index a5967dd4a..181d84149 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java @@ -20,6 +20,7 @@ package de.steamwar.inventory; import de.steamwar.core.Core; +import de.steamwar.data.CMDs; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; import org.bukkit.Bukkit; @@ -66,25 +67,25 @@ public class SWListInv extends SWInventory { setItem(45, new SWItem(SWItem.getDye(10), (byte) 10, Core.MESSAGE.parse("SWLISINV_PREVIOUS_PAGE_ACTIVE", player), (ClickType click) -> { page--; open(); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.PREVIOUS_PAGE)); } else { setItem(45, new SWItem(SWItem.getDye(8), (byte) 8, Core.MESSAGE.parse("SWLISINV_PREVIOUS_PAGE_INACTIVE", player), (ClickType click) -> { - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.PREVIOUS_PAGE)); } if (page < elements.size() / 45 - (elements.size() % 45 == 0 ? 1 : 0)) { setItem(53, new SWItem(SWItem.getDye(10), (byte) 10, Core.MESSAGE.parse("SWLISINV_NEXT_PAGE_ACTIVE", player), (ClickType click) -> { page++; open(); - }).setCustomModelData(2)); + }).setCustomModelData(CMDs.NEXT_PAGE)); } else { setItem(53, new SWItem(SWItem.getDye(8), (byte) 8, Core.MESSAGE.parse("SWLISINV_NEXT_PAGE_INACTIVE", player), (ClickType click) -> { - }).setCustomModelData(2)); + }).setCustomModelData(CMDs.NEXT_PAGE)); } } else if (!dynamicSize) { setItem(45, new SWItem(SWItem.getDye(8), (byte) 8, Core.MESSAGE.parse("SWLISINV_PREVIOUS_PAGE_INACTIVE", player), (ClickType click) -> { - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.PREVIOUS_PAGE)); setItem(53, new SWItem(SWItem.getDye(8), (byte) 8, Core.MESSAGE.parse("SWLISINV_NEXT_PAGE_INACTIVE", player), (ClickType click) -> { - }).setCustomModelData(2)); + }).setCustomModelData(CMDs.NEXT_PAGE)); } int ipageLimit = elements.size() - page * 45; diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java index 084e431a2..652ef92aa 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java @@ -128,12 +128,12 @@ public class SchematicSelector { inv.setItem(48, new SWItem(Material.BUCKET, Core.MESSAGE.parse("SCHEM_SELECTOR_OWN", player), clickType -> { this.user = SteamwarUser.get(player.getUniqueId()); openList(null); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.SCHEMATIC_GUI_OWN)); } else { inv.setItem(48, new SWItem(Material.GLASS, Core.MESSAGE.parse("SCHEM_SELECTOR_PUB", player), clickType -> { this.user = SteamwarUser.get(0); openList(null); - }).setCustomModelData(1)); + }).setCustomModelData(CMDs.SCHEMATIC_GUI_PUBLIC)); } } if(target.target.dirs) { @@ -143,9 +143,9 @@ public class SchematicSelector { }); } if(user.getId() != 0) { - inv.setItem(50, new SWItem(Material.CHEST, Core.MESSAGE.parse("SCHEM_SELECTOR_NEW_DIR", player), clickType -> createFolderIn(parent)).setCustomModelData(2)); + inv.setItem(50, new SWItem(Material.CHEST, Core.MESSAGE.parse("SCHEM_SELECTOR_NEW_DIR", player), clickType -> createFolderIn(parent)).setCustomModelData(CMDs.SCHEMATIC_GUI_NEW_DIR)); } - inv.setItem(51, new SWItem(Material.NAME_TAG, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER", player), clickType -> openFilter()).setCustomModelData(3)); + inv.setItem(51, new SWItem(Material.NAME_TAG, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER", player), clickType -> openFilter()).setCustomModelData(CMDs.SCHEMATIC_GUI_FILTER)); inv.setItem(47, new SWItem(sorting.mat, Core.MESSAGE.parse("SCHEM_SELECTOR_SORTING", player), Arrays.asList( Core.MESSAGE.parse("SCHEM_SELECTOR_SORTING_CURRENT", player, sorting.parseName(player)), Core.MESSAGE.parse("SCHEM_SELECTOR_SORTING_DIRECTION", player, Core.MESSAGE.parse(invertSorting?"SCHEM_SELECTOR_SORTING_DSC":"SCHEM_SELECTOR_SORTING_ASC", player)) @@ -156,7 +156,7 @@ public class SchematicSelector { invertSorting = !invertSorting; } openList(parent); - }).setCustomModelData(invertSorting ? 4 : 3)); + }).setCustomModelData(invertSorting ? CMDs.SCHEMATIC_SORT_DESCENDING : CMDs.SCHEMATIC_SORT_ASCENDING)); injectable.onListRender(this, inv, parent); inv.open(); From d37a14f28048628e3295452d16bd82c3f33f00f1 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 31 May 2025 10:04:21 +0200 Subject: [PATCH 026/153] Move some constants around --- .../simulator/gui/SimulatorGroupGui.java | 6 +- .../gui/SimulatorGroupSettingsGui.java | 16 ++-- .../features/simulator/gui/SimulatorGui.java | 2 +- .../simulator/gui/SimulatorObserverGui.java | 20 ++--- .../SimulatorObserverPhaseSettingsGui.java | 10 +-- .../gui/SimulatorObserverSettingsGui.java | 16 ++-- .../simulator/gui/SimulatorRedstoneGui.java | 20 ++--- .../SimulatorRedstonePhaseSettingsGui.java | 14 ++-- .../gui/SimulatorRedstoneSettingsGui.java | 16 ++-- .../simulator/gui/SimulatorSettingsGui.java | 12 +-- .../simulator/gui/SimulatorTNTGui.java | 24 +++--- .../gui/SimulatorTNTPhaseSettingsGui.java | 18 ++--- .../gui/SimulatorTNTSettingsGui.java | 17 ++--- .../Data/src/de/steamwar/data/CMDs.java | 76 ++++++++++--------- .../commands/schematiccommand/GUI.java | 2 +- .../steamwar/inventory/SchematicSelector.java | 10 +-- 16 files changed, 143 insertions(+), 136 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java index 6483aea44..e18ef66e5 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java @@ -76,7 +76,7 @@ public class SimulatorGroupGui extends SimulatorPageGui> { inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { simulatorGroup.getElements().clear(); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DELETE)); + }).setCustomModelData(CMDs.Simulator.DELETE)); inventory.setItem(4, simulatorGroup.toItem(player, clickType -> { if (simulatorGroup.getMaterial() == null) return; @@ -86,7 +86,7 @@ public class SimulatorGroupGui extends SimulatorPageGui> { inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> { new SimulatorGroupSettingsGui(player, simulator, simulatorGroup, this).open(); - }).setCustomModelData(CMDs.SIMULATOR_SETTINGS)); + }).setCustomModelData(CMDs.Simulator.SETTINGS)); boolean disabled = simulatorGroup.getMaterial() == null ? simulatorGroup.getElements().stream().allMatch(SimulatorElement::isDisabled) : simulatorGroup.isDisabled(); inventory.setItem(50, new SWItem(disabled ? Material.ENDER_PEARL : Material.ENDER_EYE, simulatorGroup.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { if (simulatorGroup.getMaterial() == null) { @@ -97,7 +97,7 @@ public class SimulatorGroupGui extends SimulatorPageGui> { simulatorGroup.setDisabled(!disabled); } SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_ENABLED_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED)); } @Override diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java index 705a76f0a..acb80f2fb 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java @@ -72,7 +72,7 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { simulatorGroup.changeBaseTicks(clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> { new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> { if (integer < 0) return false; @@ -90,7 +90,7 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { simulatorGroup.changeBaseTicks(clickType.isShiftClick() ? -5 : -1); } SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); boolean allTNT = simulatorGroup.getElements().stream().allMatch(TNTElement.class::isInstance); @@ -166,7 +166,7 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> { simulatorGroup.move(clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1, 0, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); inventory.setItem(24, new SWItem(Material.PAPER, "§eX", clickType -> { new SimulatorAnvilGui<>(player, "Relative X", "", Double::parseDouble, number -> { if(!allTNT){ @@ -180,13 +180,13 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { simulatorGroup.move(clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); //Pos Y inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> { simulatorGroup.move(0, clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); inventory.setItem(25, new SWItem(Material.PAPER, "§eY", clickType -> { new SimulatorAnvilGui<>(player, "Relative Y", "", Double::parseDouble, number -> { if(!allTNT){ @@ -200,13 +200,13 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { simulatorGroup.move(0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_ENABLED_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED)); //Pos Z inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> { simulatorGroup.move(0, 0, clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); inventory.setItem(26, new SWItem(Material.PAPER, "§eZ", clickType -> { new SimulatorAnvilGui<>(player, "Relative Z", "", Double::parseDouble, number -> { if(!allTNT){ @@ -220,6 +220,6 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { simulatorGroup.move(0, 0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGui.java index 55cc43767..c53e66130 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGui.java @@ -51,7 +51,7 @@ public class SimulatorGui extends SimulatorPageGui { })); inventory.setItem(49, new SWItem(Material.REPEATER, "§eSettings", clickType -> { new SimulatorSettingsGui(player, simulator, this).open(); - }).setCustomModelData(CMDs.SIMULATOR_SETTINGS)); + }).setCustomModelData(CMDs.Simulator.SETTINGS)); } @Override diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverGui.java index 81b3869bb..ef41229f9 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverGui.java @@ -88,7 +88,7 @@ public class SimulatorObserverGui extends SimulatorScrollGui { inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { observer.getPhases().clear(); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DELETE)); + }).setCustomModelData(CMDs.Simulator.DELETE)); // Material Chooser inventory.setItem(4, observer.toItem(player, clickType -> { @@ -98,18 +98,18 @@ public class SimulatorObserverGui extends SimulatorScrollGui { // Settings inventory.setItem(47, new SWItem(Material.REPEATER, "§eSettings", clickType -> { new SimulatorObserverSettingsGui(player, simulator, observer, this).open(); - }).setCustomModelData(CMDs.SIMULATOR_SETTINGS)); + }).setCustomModelData(CMDs.Simulator.SETTINGS)); // Enable/Disable inventory.setItem(48, new SWItem(observer.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, observer.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { observer.setDisabled(!observer.isDisabled()); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_ENABLED_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED)); // Group chooser inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> { new SimulatorGroupChooserGui(player, simulator, observer, observer.getGroup(simulator), this).open(); - }).setCustomModelData(CMDs.SIMULATOR_JOIN_GROUP)); + }).setCustomModelData(CMDs.Simulator.JOIN_GROUP)); } @Override @@ -152,15 +152,15 @@ public class SimulatorObserverGui extends SimulatorScrollGui { new SWItem(SWItem.getDye(getter.get() < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { setter.accept(Math.min(max, getter.get() + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED), + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED), observer, new SWItem(SWItem.getDye(getter.get() > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> { setter.accept(Math.max(min, getter.get() - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED), + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED), new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> { new SimulatorObserverPhaseSettingsGui(player, simulator, this.observer, observerPhase, this).open(); - }).setCustomModelData(CMDs.SIMULATOR_EDIT_ACTIVATION), + }).setCustomModelData(CMDs.Simulator.EDIT_ACTIVATION), }; } @@ -169,12 +169,12 @@ public class SimulatorObserverGui extends SimulatorScrollGui { return new SWItem[]{ new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { addNewPhase(clickType.isShiftClick()); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED), + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED), new SWItem(Material.QUARTZ, "§eObserver§8:§a New Phase", clickType -> { addNewPhase(false); - }).setCustomModelData(CMDs.SIMULATOR_NEW_PHASE), + }).setCustomModelData(CMDs.Simulator.NEW_PHASE), new SWItem(SWItem.getDye(8), "§7", clickType -> { - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED), + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED), }; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverPhaseSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverPhaseSettingsGui.java index dec581215..503d59573 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverPhaseSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverPhaseSettingsGui.java @@ -75,7 +75,7 @@ public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui { observerElement.getPhases().remove(observer); back.open(); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DELETE)); + }).setCustomModelData(CMDs.Simulator.DELETE)); int index = observerElement.getPhases().indexOf(observer); int min; @@ -99,7 +99,7 @@ public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(10, new SWItem(SWItem.getDye(offset < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { observer.setTickOffset(Math.min(max, offset + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> { new SimulatorAnvilGui<>(player, "Start at", offset + "", Integer::parseInt, integer -> { @@ -115,14 +115,14 @@ public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(28, new SWItem(SWItem.getDye(offset > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { observer.setTickOffset(Math.max(min, offset - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); //Order int order = observer.getOrder(); inventory.setItem(13, new SWItem(SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { observer.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR"); SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eActivation Order§8:§7 " + order, clickType -> { @@ -140,7 +140,7 @@ public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(31, new SWItem(SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { observer.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); // Update orientation inventory.setItem(25, new SWItem(Material.SUNFLOWER, "§7", clickType -> { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverSettingsGui.java index 71d9448e7..1abfc0906 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverSettingsGui.java @@ -69,7 +69,7 @@ public class SimulatorObserverSettingsGui extends SimulatorBaseGui { inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { observer.changeBaseTicks(clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> { new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> { if (integer < 0) return false; @@ -87,13 +87,13 @@ public class SimulatorObserverSettingsGui extends SimulatorBaseGui { observer.changeBaseTicks(clickType.isShiftClick() ? -5 : -1); } SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); //Pos X inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { observer.move(clickType.isShiftClick() ? 5 : 1, 0, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + observer.getPosition().getBlockX(), clickType -> { new SimulatorAnvilGui<>(player, "X", observer.getPosition().getBlockX() + "", Integer::parseInt, i -> { observer.getPosition().setX(i); @@ -104,13 +104,13 @@ public class SimulatorObserverSettingsGui extends SimulatorBaseGui { inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { observer.move(clickType.isShiftClick() ? -5 : -1, 0, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); //Pos Y inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { observer.move(0, clickType.isShiftClick() ? 5 : 1, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_ENABLED_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED)); inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + observer.getPosition().getBlockY(), clickType -> { new SimulatorAnvilGui<>(player, "Y", observer.getPosition().getBlockY() + "", Integer::parseInt, i -> { observer.getPosition().setY(i); @@ -121,13 +121,13 @@ public class SimulatorObserverSettingsGui extends SimulatorBaseGui { inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { observer.move(0, clickType.isShiftClick() ? -5 : -1, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); //Pos Z inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { observer.move(0, 0, clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_ENABLED_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED)); inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + observer.getPosition().getBlockZ(), clickType -> { new SimulatorAnvilGui<>(player, "Z", observer.getPosition().getBlockZ() + "", Integer::parseInt, i -> { observer.getPosition().setZ(i); @@ -138,6 +138,6 @@ public class SimulatorObserverSettingsGui extends SimulatorBaseGui { inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { observer.move(0, 0, clickType.isShiftClick() ? -5 : -1); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java index c0809cfda..29589b8e2 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java @@ -94,7 +94,7 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { redstone.getPhases().clear(); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DELETE)); + }).setCustomModelData(CMDs.Simulator.DELETE)); // Material Chooser inventory.setItem(4, redstone.toItem(player, clickType -> { @@ -104,18 +104,18 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { new SimulatorRedstoneSettingsGui(player, simulator, redstone, this).open(); - }).setCustomModelData(CMDs.SIMULATOR_SETTINGS)); + }).setCustomModelData(CMDs.Simulator.SETTINGS)); // Enable/Disable inventory.setItem(48, new SWItem(redstone.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, redstone.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { redstone.setDisabled(!redstone.isDisabled()); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_ENABLED_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED)); // Group chooser inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> { new SimulatorGroupChooserGui(player, simulator, redstone, redstone.getGroup(simulator), this).open(); - }).setCustomModelData(CMDs.SIMULATOR_JOIN_GROUP)); + }).setCustomModelData(CMDs.Simulator.JOIN_GROUP)); } @Override @@ -167,15 +167,15 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { setter.accept(Math.min(max, getter.get() + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED), + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED), redstone, new SWItem(SWItem.getDye(getter.get() > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> { setter.accept(Math.max(min, getter.get() - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED), + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED), new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> { new SimulatorRedstonePhaseSettingsGui(player, simulator, this.redstone, redstoneSubPhase.phase, this).open(); - }).setCustomModelData(CMDs.SIMULATOR_EDIT_ACTIVATION), + }).setCustomModelData(CMDs.Simulator.EDIT_ACTIVATION), }; } @@ -184,12 +184,12 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { addNewPhase(clickType.isShiftClick()); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED), + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED), new SWItem(Material.REDSTONE, "§eRedstone§8:§a New Phase", clickType -> { addNewPhase(false); - }).setCustomModelData(CMDs.SIMULATOR_NEW_PHASE), + }).setCustomModelData(CMDs.Simulator.NEW_PHASE), new SWItem(SWItem.getDye(8), "§7", clickType -> { - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED), + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED), }; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java index dd957d354..6994d4e88 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java @@ -73,7 +73,7 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { redstoneElement.getPhases().remove(redstone); back.open(); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DELETE)); + }).setCustomModelData(CMDs.Simulator.DELETE)); int index = redstoneElement.getPhases().indexOf(redstone); int min; @@ -100,7 +100,7 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(10, new SWItem(SWItem.getDye(offset < maxOffset ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.setTickOffset(Math.min(maxOffset, offset + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> { new SimulatorAnvilGui<>(player, "Start at", offset + "", Integer::parseInt, integer -> { @@ -116,14 +116,14 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(28, new SWItem(SWItem.getDye(offset > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.setTickOffset(Math.max(min, offset - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); //Lifetime int lifetime = redstone.getLifetime(); inventory.setItem(11, new SWItem(SWItem.getDye(lifetime < maxLifetime ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.setLifetime(Math.min(maxLifetime, lifetime + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eActivation Time§8:§7 " + lifetime, clickType -> { new SimulatorAnvilGui<>(player, "Activation Time", lifetime + "", Integer::parseInt, integer -> { @@ -139,14 +139,14 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(29, new SWItem(SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.setLifetime(Math.max(0, lifetime - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); //Order int order = redstone.getOrder(); inventory.setItem(13, new SWItem(SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR"); SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eActivation Order§8:§7 " + order, clickType -> { @@ -164,6 +164,6 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(31, new SWItem(SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneSettingsGui.java index 4b1f6ed36..629e2aa58 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneSettingsGui.java @@ -68,7 +68,7 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.changeBaseTicks(clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> { new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> { if (integer < 0) return false; @@ -86,13 +86,13 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { redstone.changeBaseTicks(clickType.isShiftClick() ? -5 : -1); } SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); //Pos X inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.move(clickType.isShiftClick() ? 5 : 1, 0, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + redstone.getPosition().getBlockX(), clickType -> { new SimulatorAnvilGui<>(player, "X", redstone.getPosition().getBlockX() + "", Integer::parseInt, i -> { redstone.getPosition().setX(i); @@ -103,13 +103,13 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.move(clickType.isShiftClick() ? -5 : -1, 0, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); //Pos Y inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.move(0, clickType.isShiftClick() ? 5 : 1, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + redstone.getPosition().getBlockY(), clickType -> { new SimulatorAnvilGui<>(player, "Y", redstone.getPosition().getBlockY() + "", Integer::parseInt, i -> { redstone.getPosition().setY(i); @@ -120,13 +120,13 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.move(0, clickType.isShiftClick() ? -5 : -1, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); //Pos Z inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.move(0, 0, clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + redstone.getPosition().getBlockZ(), clickType -> { new SimulatorAnvilGui<>(player, "Z", redstone.getPosition().getBlockZ() + "", Integer::parseInt, i -> { redstone.getPosition().setZ(i); @@ -137,6 +137,6 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.move(0, 0, clickType.isShiftClick() ? -5 : -1); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java index 87ecb2249..4c442ac41 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java @@ -65,36 +65,36 @@ public class SimulatorSettingsGui extends SimulatorBaseGui { inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { simulator.move(clickType.isShiftClick() ? 5 : 1, 0, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); inventory.setItem(24, new SWItem(Material.PAPER, "§eX", clickType -> { })); inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { simulator.move(clickType.isShiftClick() ? -5 : -1, 0, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); //Pos Y inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { simulator.move(0, clickType.isShiftClick() ? 5 : 1, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); inventory.setItem(25, new SWItem(Material.PAPER, "§eY", clickType -> { })); inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { simulator.move(0, clickType.isShiftClick() ? -5 : -1, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); //Pos Z inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { simulator.move(0, 0, clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); inventory.setItem(26, new SWItem(Material.PAPER, "§eZ", clickType -> { })); inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { simulator.move(0, 0, clickType.isShiftClick() ? -5 : -1); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java index 30fbe20c1..75c2c8761 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java @@ -87,7 +87,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui { inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { tnt.getPhases().clear(); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DELETE)); + }).setCustomModelData(CMDs.Simulator.DELETE)); // Material Chooser inventory.setItem(4, tnt.toItem(player, clickType -> { @@ -96,11 +96,11 @@ public class SimulatorTNTGui extends SimulatorScrollGui { inventory.setItem(47, new SWItem(Material.REPEATER, "§eSettings", clickType -> { new SimulatorTNTSettingsGui(player, simulator, tnt, this).open(); - }).setCustomModelData(CMDs.SIMULATOR_SETTINGS)); + }).setCustomModelData(CMDs.Simulator.SETTINGS)); inventory.setItem(48, new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { tnt.setDisabled(!tnt.isDisabled()); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_ENABLED_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED)); inventory.setItem(49, new SWItem(Material.CALIBRATED_SCULK_SENSOR, "§eCreate Stab", click -> { new SimulatorAnvilGui<>(player, "Depth Limit", "", Integer::parseInt, depthLimit -> { if (depthLimit <= 0) return false; @@ -108,17 +108,17 @@ public class SimulatorTNTGui extends SimulatorScrollGui { SimulatorWatcher.update(simulator); return true; }, null).open(); - }).setCustomModelData(CMDs.SIMULATOR_CREATE_STAB)); + }).setCustomModelData(CMDs.Simulator.CREATE_STAB)); inventory.setItem(50, new SWItem(Material.CHEST, parent.getElements().size() == 1 ? "§eMake Group" : "§eAdd another TNT to Group", clickType -> { TNTElement tntElement = new TNTElement(tnt.getPosition().clone()); tntElement.add(new TNTPhase()); parent.add(tntElement); new SimulatorGroupGui(player, simulator, parent, new SimulatorGui(player, simulator)).open(); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_MAKE_GROUP)); + }).setCustomModelData(CMDs.Simulator.MAKE_GROUP)); inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> { new SimulatorGroupChooserGui(player, simulator, tnt, tnt.getGroup(simulator), this).open(); - }).setCustomModelData(CMDs.SIMULATOR_JOIN_GROUP)); + }).setCustomModelData(CMDs.Simulator.JOIN_GROUP)); } @Override @@ -137,15 +137,15 @@ public class SimulatorTNTGui extends SimulatorScrollGui { new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { tntSetting.setCount(tntSetting.getCount() + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED), + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED), tnt, new SWItem(SWItem.getDye(tntSetting.getCount() > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> { tntSetting.setCount(Math.max(1, tntSetting.getCount() - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED), + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED), new SWItem(Material.ANVIL, "§eEdit Phase", clickType -> { new SimulatorTNTPhaseSettingsGui(player, simulator, this.tnt, tntSetting, this).open(); - }).setCustomModelData(CMDs.SIMULATOR_EDIT_ACTIVATION), + }).setCustomModelData(CMDs.Simulator.EDIT_ACTIVATION), }; } @@ -154,12 +154,12 @@ public class SimulatorTNTGui extends SimulatorScrollGui { return new SWItem[]{ new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { addNewPhase(clickType.isShiftClick()); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED), + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED), new SWItem(Material.GUNPOWDER, "§eTNT§8:§a New Phase", clickType -> { addNewPhase(false); - }).setCustomModelData(CMDs.SIMULATOR_NEW_PHASE), + }).setCustomModelData(CMDs.Simulator.NEW_PHASE), new SWItem(SWItem.getDye(8), "§7", clickType -> { - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED), + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED), }; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java index 25ca10dc5..5b4775d3d 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java @@ -73,14 +73,14 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { tntElement.getPhases().remove(tnt); back.open(); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DELETE)); + }).setCustomModelData(CMDs.Simulator.DELETE)); //Count int count = tnt.getCount(); inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { tnt.setCount(count + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); SWItem countItem = new SWItem(Material.TNT, "§eCount§8:§7 " + count, clickType -> { new SimulatorAnvilGui<>(player, "Count", count + "", Integer::parseInt, integer -> { @@ -96,14 +96,14 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(27, new SWItem(SWItem.getDye(count > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { tnt.setCount(Math.max(1, count - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); //Tick Offset int offset = tnt.getTickOffset(); inventory.setItem(10, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { tnt.setTickOffset(offset + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> { new SimulatorAnvilGui<>(player, "Start at", offset + "", Integer::parseInt, integer -> { @@ -119,14 +119,14 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(28, new SWItem(SWItem.getDye(offset > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { tnt.setTickOffset(Math.max(0, offset - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); //Lifetime int lifetime = tnt.getLifetime(); inventory.setItem(11, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { tnt.setLifetime(lifetime + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eLifetime§8:§7 " + lifetime, clickType -> { new SimulatorAnvilGui<>(player, "Lifetime", lifetime + "", Integer::parseInt, integer -> { @@ -142,14 +142,14 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(29, new SWItem(SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { tnt.setLifetime(Math.max(1, lifetime - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); //Order int order = tnt.getOrder(); inventory.setItem(13, new SWItem(SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { tnt.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR"); SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eCalculation Order§8:§7 " + order, clickType -> { @@ -167,7 +167,7 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(31, new SWItem(SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { tnt.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); //Jump SWItem jumpX = new SWItem(tnt.isXJump() ? Material.LIME_WOOL : Material.RED_WOOL, "§7TNT §eJump X§8: " + (tnt.isZJump() ? "§aon" : "§coff"), clickType -> { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java index a897c96c3..04a3334e8 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java @@ -28,7 +28,6 @@ import de.steamwar.data.CMDs; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; -import org.bukkit.util.Vector; import java.util.ArrayList; import java.util.Arrays; @@ -78,7 +77,7 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { tnt.changeBaseTicks(clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> { new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> { if (integer < 0) return false; @@ -96,7 +95,7 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { tnt.changeBaseTicks(clickType.isShiftClick() ? -5 : -1); } SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); // Subpixel Alignment inventory.setItem(21, new SWItem(Material.SUNFLOWER, "§7Align§8: §eCenter", clickType -> { @@ -139,7 +138,7 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> { tnt.move(clickType.isShiftClick() ? 0.0625 : 1, 0, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + tnt.getPosition().getX(), clickType -> { new SimulatorAnvilGui<>(player, "X", tnt.getPosition().getX() + "", Double::parseDouble, d -> { tnt.getPosition().setX(d); @@ -150,13 +149,13 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { tnt.move(clickType.isShiftClick() ? -0.0625 : -1, 0, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); // Pos Y inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> { tnt.move(0, clickType.isShiftClick() ? 0.0625 : 1, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + tnt.getPosition().getY(), clickType -> { new SimulatorAnvilGui<>(player, "Y", tnt.getPosition().getY() + "", Double::parseDouble, d -> { tnt.getPosition().setY(d); @@ -167,13 +166,13 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { tnt.move(0, clickType.isShiftClick() ? -0.0625 : -1, 0); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); // Pos Z inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> { tnt.move(0, 0, clickType.isShiftClick() ? 0.0625 : 1); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_INCREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + tnt.getPosition().getZ(), clickType -> { new SimulatorAnvilGui<>(player, "Z", tnt.getPosition().getZ() + "", Double::parseDouble, d -> { tnt.getPosition().setZ(d); @@ -184,6 +183,6 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { tnt.move(0, 0, clickType.isShiftClick() ? -0.0625 : -1); SimulatorWatcher.update(simulator); - }).setCustomModelData(CMDs.SIMULATOR_DECREMENT_OR_DISABLED)); + }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); } } diff --git a/CommonCore/Data/src/de/steamwar/data/CMDs.java b/CommonCore/Data/src/de/steamwar/data/CMDs.java index c790ea309..996df1302 100644 --- a/CommonCore/Data/src/de/steamwar/data/CMDs.java +++ b/CommonCore/Data/src/de/steamwar/data/CMDs.java @@ -31,54 +31,62 @@ public interface CMDs { // Material.DYE (Color 10/8) int NEXT_PAGE = 2; - // Material.BARRIER - int SIMULATOR_DELETE = 1; + // BauSystem Simulator + interface Simulator { - // Material.REPEATER - int SIMULATOR_SETTINGS = 1; + // Material.BARRIER + int DELETE = 1; - // Material.ENDER_PEARL and Material.ENDER_EYE - int SIMULATOR_ENABLED_OR_DISABLED = 1; + // Material.REPEATER + int SETTINGS = 1; - // Material.DYE (Color 10/8) - int SIMULATOR_INCREMENT_OR_DISABLED = 3; + // Material.ENDER_PEARL and Material.ENDER_EYE + int ENABLED_OR_DISABLED = 1; - // Material.DYE (Color 1/8) - int SIMULATOR_DECREMENT_OR_DISABLED = 3; + // Material.DYE (Color 10/8) + int INCREMENT_OR_DISABLED = 3; - // Material.LEAD - int SIMULATOR_JOIN_GROUP = 1; + // Material.DYE (Color 1/8) + int DECREMENT_OR_DISABLED = 3; - // Material.ANVIL - int SIMULATOR_EDIT_ACTIVATION = 1; + // Material.LEAD + int JOIN_GROUP = 1; - // Material.QUARTZ, Material.REDSTONE, Material.GUNPOWDER - int SIMULATOR_NEW_PHASE = 1; + // Material.ANVIL + int EDIT_ACTIVATION = 1; - // Material.CALIBRATED_SCULK_SENSOR - int SIMULATOR_CREATE_STAB = 1; + // Material.QUARTZ, Material.REDSTONE, Material.GUNPOWDER + int NEW_PHASE = 1; - // Material.CHEST - int SIMULATOR_MAKE_GROUP = 1; + // Material.CALIBRATED_SCULK_SENSOR + int CREATE_STAB = 1; - // Material.LEAD - int SCHEMATIC_GUI_BACK = 2; + // Material.CHEST + int MAKE_GROUP = 1; + } - // Material.BUCKET - int SCHEMATIC_GUI_OWN = 1; + // Schematic System + interface Schematic { - // Material.GLASS - int SCHEMATIC_GUI_PUBLIC = 1; + // Material.LEAD + int BACK = 2; - // Material.CHEST - int SCHEMATIC_GUI_NEW_DIR = 2; + // Material.BUCKET + int OWN_SCHEMS = 1; - // Material.NAME_TAG - int SCHEMATIC_GUI_FILTER = 3; + // Material.GLASS + int PUBLIC_SCHEMS = 1; - // Material.PAPER, Material.CAULDRON, Material.CLOCK - int SCHEMATIC_SORT_ASCENDING = 3; + // Material.CHEST + int NEW_DIR = 2; - // Material.PAPER, Material.CAULDRON, Material.CLOCK - int SCHEMATIC_SORT_DESCENDING = 4; + // Material.NAME_TAG + int FILTER = 3; + + // Material.PAPER, Material.CAULDRON, Material.CLOCK + int SORT_ASCENDING = 3; + + // Material.PAPER, Material.CAULDRON, Material.CLOCK + int SORT_DESCENDING = 4; + } } diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java index 8a6cded6d..4160ad051 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java @@ -103,7 +103,7 @@ public class GUI { inv.setItem(9, new SWItem(SWItem.getMaterial("LEASH"), SchematicSystem.MESSAGE.parse("GUI_INFO_BACK", player), clickType -> { back.reOpen(); - }).setCustomModelData(CMDs.SCHEMATIC_GUI_BACK)); + }).setCustomModelData(CMDs.Schematic.BACK)); if(node.getOwner() == user.getId()){ if(!node.isDir() && node.getSchemtype().writeable()){ diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java index 652ef92aa..6d7a6201d 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java @@ -128,12 +128,12 @@ public class SchematicSelector { inv.setItem(48, new SWItem(Material.BUCKET, Core.MESSAGE.parse("SCHEM_SELECTOR_OWN", player), clickType -> { this.user = SteamwarUser.get(player.getUniqueId()); openList(null); - }).setCustomModelData(CMDs.SCHEMATIC_GUI_OWN)); + }).setCustomModelData(CMDs.Schematic.OWN_SCHEMS)); } else { inv.setItem(48, new SWItem(Material.GLASS, Core.MESSAGE.parse("SCHEM_SELECTOR_PUB", player), clickType -> { this.user = SteamwarUser.get(0); openList(null); - }).setCustomModelData(CMDs.SCHEMATIC_GUI_PUBLIC)); + }).setCustomModelData(CMDs.Schematic.PUBLIC_SCHEMS)); } } if(target.target.dirs) { @@ -143,9 +143,9 @@ public class SchematicSelector { }); } if(user.getId() != 0) { - inv.setItem(50, new SWItem(Material.CHEST, Core.MESSAGE.parse("SCHEM_SELECTOR_NEW_DIR", player), clickType -> createFolderIn(parent)).setCustomModelData(CMDs.SCHEMATIC_GUI_NEW_DIR)); + inv.setItem(50, new SWItem(Material.CHEST, Core.MESSAGE.parse("SCHEM_SELECTOR_NEW_DIR", player), clickType -> createFolderIn(parent)).setCustomModelData(CMDs.Schematic.NEW_DIR)); } - inv.setItem(51, new SWItem(Material.NAME_TAG, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER", player), clickType -> openFilter()).setCustomModelData(CMDs.SCHEMATIC_GUI_FILTER)); + inv.setItem(51, new SWItem(Material.NAME_TAG, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER", player), clickType -> openFilter()).setCustomModelData(CMDs.Schematic.FILTER)); inv.setItem(47, new SWItem(sorting.mat, Core.MESSAGE.parse("SCHEM_SELECTOR_SORTING", player), Arrays.asList( Core.MESSAGE.parse("SCHEM_SELECTOR_SORTING_CURRENT", player, sorting.parseName(player)), Core.MESSAGE.parse("SCHEM_SELECTOR_SORTING_DIRECTION", player, Core.MESSAGE.parse(invertSorting?"SCHEM_SELECTOR_SORTING_DSC":"SCHEM_SELECTOR_SORTING_ASC", player)) @@ -156,7 +156,7 @@ public class SchematicSelector { invertSorting = !invertSorting; } openList(parent); - }).setCustomModelData(invertSorting ? CMDs.SCHEMATIC_SORT_DESCENDING : CMDs.SCHEMATIC_SORT_ASCENDING)); + }).setCustomModelData(invertSorting ? CMDs.Schematic.SORT_DESCENDING : CMDs.Schematic.SORT_ASCENDING)); injectable.onListRender(this, inv, parent); inv.open(); From c3db2b7f86980fcd60626a4542203579ac622ba8 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 1 Jun 2025 14:36:49 +0200 Subject: [PATCH 027/153] VelocityCore/src/de/steamwar/velocitycore/listeners/EventModeListener.java aktualisiert --- .../de/steamwar/velocitycore/listeners/EventModeListener.java | 1 - 1 file changed, 1 deletion(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/EventModeListener.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/EventModeListener.java index 688f3885d..cdc76b1e3 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/EventModeListener.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/EventModeListener.java @@ -96,7 +96,6 @@ public class EventModeListener extends BasicListener { SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - EventFight.clearActiveFightsCache(); List activeFights = EventFight.getActiveFights(); if (activeFights.stream() From 1014df5f31f5e757288448a4bdb974f9e20e6230 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 3 Jun 2025 23:39:16 +0200 Subject: [PATCH 028/153] PR Stuff --- .../SQL/src/de/steamwar/sql/CheckedSchematic.java | 14 +------------- VelocityCore/src/de/steamwar/messages/Chatter.java | 4 +--- .../velocitycore/commands/CheckCommand.java | 14 +++++++------- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java b/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java index de68377a9..0037d8805 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java +++ b/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java @@ -40,20 +40,8 @@ public class CheckedSchematic { private static final SelectStatement getUnseen = new SelectStatement<>(table, "SELECT * FROM CheckedSchematic WHERE Seen = 0 AND NodeOwner = ? ORDER BY StartTime DESC"); private static final Statement updateSeen = new Statement("UPDATE CheckedSchematic SET Seen = ? WHERE StartTime = ? AND EndTime = ? AND NodeName = ?"); - public static void create(int nodeId, String name, int owner, int validator, Timestamp startTime, Timestamp endTime, String reason, boolean seen, String nodeType) { - insert.update(nodeId, owner, name, validator, startTime, endTime, reason, seen, nodeType); - } - - public static void create(int nodeId, String name, int owner, int validator, Timestamp startTime, Timestamp endTime, String reason, String nodeType) { - create(nodeId, name, owner, validator, startTime, endTime, reason, true, nodeType); - } - public static void create(SchematicNode node, int validator, Timestamp startTime, Timestamp endTime, String reason, boolean seen) { - create(node.getId(), node.getName(), node.getOwner(), validator, startTime, endTime, reason, seen, node.getSchemtype().toDB()); - } - - public static void create(SchematicNode node, int validator, Timestamp startTime, Timestamp endTime, String reason) { - create(node.getId(), node.getName(), node.getOwner(), validator, startTime, endTime, reason, true, node.getSchemtype().toDB()); + insert.update(node.getId(), node.getName(), node.getOwner(), validator, startTime, endTime, reason, seen, node.getSchemtype().toDB()); } public static List getLastDeclinedOfNode(int node) { diff --git a/VelocityCore/src/de/steamwar/messages/Chatter.java b/VelocityCore/src/de/steamwar/messages/Chatter.java index f5a0b0f2f..5de34d0c7 100644 --- a/VelocityCore/src/de/steamwar/messages/Chatter.java +++ b/VelocityCore/src/de/steamwar/messages/Chatter.java @@ -85,14 +85,12 @@ public interface Chatter { else return withPlayer.apply(player); } - default boolean withPlayerOrOffline(Consumer withPlayer, Runnable withOffline) { + default void withPlayerOrOffline(Consumer withPlayer, Runnable withOffline) { Player player = getPlayer(); if(player == null) { withOffline.run(); - return false; } else { withPlayer.accept(player); - return true; } } default void withPlayer(Consumer function) { diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java index f8faddbe5..593dad2ca 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java @@ -41,7 +41,7 @@ import java.time.Instant; import java.util.List; import java.util.*; import java.util.concurrent.TimeUnit; -import java.util.function.Supplier; +import java.util.function.BooleanSupplier; import java.util.logging.Level; public class CheckCommand extends SWCommand { @@ -240,26 +240,26 @@ public class CheckCommand extends SWCommand { private void accept(){ concludeCheckSession("freigegeben", fightTypes.get(schematic.getSchemtype()), () -> { Chatter owner = Chatter.of(SteamwarUser.get(schematic.getOwner()).getUUID()); - boolean isOnline = owner.withPlayerOrOffline( + owner.withPlayerOrOffline( player -> owner.system("CHECK_ACCEPTED", schematic.getSchemtype().name(), schematic.getName()), () -> DiscordAlert.send(owner, Color.GREEN, new Message("DC_TITLE_SCHEMINFO"), new Message("DC_SCHEM_ACCEPT", schematic.getName()), true) ); notifyTeam(new Message("CHECK_ACCEPTED_TEAM", schematic.getName(), owner.user().getUserName())); - return isOnline; + return owner.getPlayer() != null; }); } private void decline(String reason){ concludeCheckSession(reason, SchematicType.Normal, () -> { Chatter owner = Chatter.of(SteamwarUser.get(schematic.getOwner()).getUUID()); - boolean isOnline = owner.withPlayerOrOffline( + owner.withPlayerOrOffline( player -> owner.system("CHECK_DECLINED", schematic.getSchemtype().name(), schematic.getName(), reason), () -> DiscordAlert.send(owner, Color.RED, new Message("DC_TITLE_SCHEMINFO"), new Message("DC_SCHEM_DECLINE", schematic.getName(), reason), false) ); notifyTeam(new Message("CHECK_DECLINED_TEAM", schematic.getName(), owner.user().getUserName(), reason)); - return isOnline; + return owner.getPlayer() != null; }); } @@ -272,9 +272,9 @@ public class CheckCommand extends SWCommand { concludeCheckSession("Prüfvorgang abgebrochen", null, () -> true); } - private void concludeCheckSession(String reason, SchematicType type, Supplier sendMessageIsOnline) { + private void concludeCheckSession(String reason, SchematicType type, BooleanSupplier sendMessageIsOnline) { if(SchematicNode.getSchematicNode(schematic.getId()) != null) { - CheckedSchematic.create(schematic, checker.user().getId(), startTime, Timestamp.from(Instant.now()), reason, sendMessageIsOnline.get()); + CheckedSchematic.create(schematic, checker.user().getId(), startTime, Timestamp.from(Instant.now()), reason, sendMessageIsOnline.getAsBoolean()); if(type != null) schematic.setSchemtype(type); } From 5cc417c43c820c27c4a769ae6ca9b960f382ce32 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 5 Jun 2025 23:41:01 +0200 Subject: [PATCH 029/153] Add declined question handling in CheckCommand - Implemented tracking of declined questions during checks. - Updated messaging logic to display declined questions to users. - Added new translations for decline-related messages. --- .../steamwar/messages/BungeeCore.properties | 3 ++ .../messages/BungeeCore_de.properties | 2 + .../velocitycore/commands/CheckCommand.java | 42 +++++++++++++++++-- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties index c46cd3177..5b4b2400a 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties @@ -325,12 +325,15 @@ CHECK_ABORT=§aThe test operation was canceled! CHECK_NEXT=Next question CHECK_ACCEPT=Accept CHECK_DECLINE=Decline +CHECK_MARK_DECLINE=Mark Decline CHECK_RANK=§aRank {0}: {1} CHECK_RANK_HOVER=§aAccept with given rank CHECK_ACCEPTED=§aYour §e{0} {1} §ewas accepted§8! CHECK_ACCEPTED_TEAM=§7The schematic §e{0} §7from §e{1} §7is now approved! CHECK_DECLINED=§cYour §e{0} {1} §cwas declined§8: §c{2} CHECK_DECLINED_TEAM=§7The schematic §e{0} §7from §e{1} §7is now declined because §e{2}§7! +CHECK_DECLINED_QUESTIONS=§fQuestions answered declined: +CHECK_DECLINED_QUESTION_FORMAT=§c{0}: {1} #HistoricCommand HISTORIC_BROADCAST=§7Historic §e{0} §7fight by §e{1}§8! diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties index 51a47cc3d..456d961a1 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties @@ -307,12 +307,14 @@ CHECK_ABORT=§aDer Prüfvorgang wurde abgebrochen! CHECK_NEXT=Nächste Frage CHECK_ACCEPT=Annehmen CHECK_DECLINE=Ablehnen +CHECK_MARK_DECLINE=Ablehnen Markieren CHECK_RANK=§aRang {0}: {1} CHECK_RANK_HOVER=§aMit diesem Rang freigeben CHECK_ACCEPTED=§aDein §e{0} {1} §ewurde freigegeben§8! CHECK_ACCEPTED_TEAM=§7Die Schematic §e{0} §7von §e{1} §7ist nun freigegeben! CHECK_DECLINED=§cDein §e{0} {1} §cwurde abgelehnt§8: §c{2} CHECK_DECLINED_TEAM=§7Die Schematic §e{0} §7von §e{1} §7wurde aufgrund von §e{2} §7abgelehnt! +CHECK_DECLINED_QUESTIONS=§fAls abgelehnt markierte Fragen: #HistoricCommand HISTORIC_BROADCAST=§7Historischer §e{0}§8-§7Kampf von §e{1}§8! diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java index c678fa4c2..2bff28bb2 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java @@ -164,6 +164,14 @@ public class CheckCommand extends SWCommand { next(sender); } + @Register(value = "decline", description = "CHECK_HELP_DECLINE") + public void decline(PlayerChatter sender) { + if(notChecking(sender.getPlayer())) + return; + + currentCheckers.get(sender.getPlayer().getUniqueId()).markDeclined(); + } + @Register(value = "decline", description = "CHECK_HELP_DECLINE") public void decline(PlayerChatter sender, String... message) { if(notChecking(sender.getPlayer())) @@ -200,6 +208,8 @@ public class CheckCommand extends SWCommand { private final SchematicNode schematic; private final Timestamp startTime; private final ListIterator checkList; + private String currentQuestion; + private final List declinedQuestions = new ArrayList<>(); private CheckSession(PlayerChatter checker, SchematicNode schematic){ this.checker = checker; @@ -220,20 +230,44 @@ public class CheckCommand extends SWCommand { private void next() { if(!checkList.hasNext()){ - accept(); + if (declinedQuestions.isEmpty()) { + accept(); + } else { + checker.system("CHECK_DECLINED_QUESTIONS"); + int i = 1; + for (String s : declinedQuestions) { + checker.prefixless("CHECK_DECLINED_QUESTION_FORMAT", i++, s); + } + declinedQuestions.clear(); + checker.sendMessage(Component + .text(checker.parseToPlain("CHECK_ACCEPT")) + .color(NamedTextColor.GREEN) + .clickEvent(ClickEvent.suggestCommand("/check accept")) + .append(Component + .text(" " + checker.parseToPlain("CHECK_DECLINE")) + .color(NamedTextColor.RED) + .clickEvent(ClickEvent.suggestCommand("/check decline ")))); + } return; } - checker.prefixless("PLAIN_STRING", checkList.next()); + currentQuestion = checkList.next(); + + checker.prefixless("PLAIN_STRING", currentQuestion); checker.sendMessage(Component .text(checker.parseToPlain(checkList.hasNext() ? "CHECK_NEXT" : "CHECK_ACCEPT")) .color(NamedTextColor.GREEN) .clickEvent(ClickEvent.runCommand("/check next")) .append(Component - .text(" " + checker.parseToPlain("CHECK_DECLINE")) + .text(" " + checker.parseToPlain("CHECK_MARK_DECLINE")) .color(NamedTextColor.RED) - .clickEvent(ClickEvent.suggestCommand("/check decline ")))); + .clickEvent(ClickEvent.runCommand("/check decline")))); + } + + private void markDeclined() { + declinedQuestions.add(currentQuestion); + next(); } private void accept(){ From 761977c90af5fc7b9328f7de7b812eb78c88744c Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 8 Jun 2025 16:42:45 +0200 Subject: [PATCH 030/153] BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java aktualisiert --- .../bausystem/features/script/lua/SteamWarLuaPlugin.java | 1 + 1 file changed, 1 insertion(+) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java index c047531c3..16deeda1f 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java @@ -166,6 +166,7 @@ public class SteamWarLuaPlugin extends TwoArgFunction { env.set("rawlen", NIL); env.set("rawset", NIL); env.set("xpcall", NIL); + env.set("require", NIL); return null; } From 1a570dca172f39a8aa8e2b2ee63a59a19b02a132 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 8 Jun 2025 18:18:44 +0200 Subject: [PATCH 031/153] BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java aktualisiert --- .../bausystem/features/script/lua/SteamWarLuaPlugin.java | 1 + 1 file changed, 1 insertion(+) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java index 16deeda1f..c33709048 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java @@ -167,6 +167,7 @@ public class SteamWarLuaPlugin extends TwoArgFunction { env.set("rawset", NIL); env.set("xpcall", NIL); env.set("require", NIL); + env.set("package", NIL); return null; } From dfd9febd8c470bba72628813a285e4e3a8f1985f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 8 Jun 2025 22:34:05 +0200 Subject: [PATCH 032/153] Remove Shields from Check Arena --- .../fightsystem/utils/WorldeditWrapper14.java | 15 +++++++++++++++ .../fightsystem/utils/WorldeditWrapper8.java | 17 +++++++++++++---- .../fightsystem/fight/FightSchematic.java | 5 +++++ .../fightsystem/utils/WorldeditWrapper.java | 3 +++ 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java b/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java index 9a0ae4b52..e26c8525e 100644 --- a/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java +++ b/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java @@ -21,9 +21,11 @@ package de.steamwar.fightsystem.utils; import com.sk89q.jnbt.NBTInputStream; import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.bukkit.BukkitBlockRegistry; import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; @@ -39,6 +41,7 @@ import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; @@ -47,6 +50,7 @@ import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; import org.bukkit.DyeColor; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.util.Vector; import java.io.ByteArrayOutputStream; @@ -147,4 +151,15 @@ public class WorldeditWrapper14 implements WorldeditWrapper { new SchematicData(schem).saveFromBytes(outputStream.toByteArray(), NodeData.SchematicFormat.SPONGE_V2); } + + @Override + public void fillRegion(org.bukkit.World world, Region region, Material material) { + EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(world), -1); + try { + e.setBlocks(new CuboidRegion(new BukkitWorld(world), BlockVector3.at(region.getMinX(), region.getMinY(), region.getMinZ()), BlockVector3.at(region.getMaxX(), region.getMaxY(), region.getMaxZ())), BlockTypes.get(material.name()).getDefaultState().toBaseBlock()); + } catch (MaxChangedBlocksException ex) { + throw new RuntimeException(ex); + } + e.flushSession(); + } } diff --git a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java index 018552f26..58d51350a 100644 --- a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java +++ b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java @@ -20,11 +20,9 @@ package de.steamwar.fightsystem.utils; import com.sk89q.jnbt.NBTInputStream; -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.*; import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.blocks.BlockType; import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; @@ -145,4 +143,15 @@ public class WorldeditWrapper8 implements WorldeditWrapper { new SchematicData(schem).saveFromBytes(outputStream.toByteArray(), NodeData.SchematicFormat.MCEDIT); } + + @Override + public void fillRegion(org.bukkit.World world, Region region, Material material) { + EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(world), -1); + try { + e.setBlocks(new CuboidRegion(new BukkitWorld(world), BlockVector.toBlockPoint(region.getMinX(), region.getMinY(), region.getMinZ()), BlockVector.toBlockPoint(region.getMaxX(), region.getMaxY(), region.getMaxZ())), new BaseBlock(BlockType.lookup(material.name()).getID())); + } catch (MaxChangedBlocksException ex) { + throw new RuntimeException(ex); + } + e.flushQueue(); + } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index 5e84ccdc9..2c8fc7161 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -140,6 +140,11 @@ public class FightSchematic extends StateDependent { FreezeWorld freezer = new FreezeWorld(); team.teleportToSpawn(); + + if(Config.mode == ArenaMode.CHECK) { + WorldeditWrapper.impl.fillRegion(Config.world, region, Material.AIR); + } + Vector dims = WorldeditWrapper.impl.getDimensions(clipboard); WorldeditWrapper.impl.pasteClipboard( clipboard, diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java index 83c688039..f486c4d64 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java @@ -27,6 +27,8 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.sql.SchematicNode; import org.bukkit.DyeColor; import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.util.Vector; import java.io.IOException; @@ -40,4 +42,5 @@ public interface WorldeditWrapper { Vector getDimensions(Clipboard clipboard); Clipboard loadChar(String charName) throws IOException; void saveSchem(SchematicNode schem, Region region, int minY) throws WorldEditException; + void fillRegion(World world, Region region, Material material); } From 428c63429c9a69b5f2acee21d7470141a2c9ebce Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Tue, 10 Jun 2025 17:26:20 +0200 Subject: [PATCH 033/153] Add 'queuerestart' command --- .../de/steamwar/persistent/Persistent.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/VelocityCore/Persistent/src/de/steamwar/persistent/Persistent.java b/VelocityCore/Persistent/src/de/steamwar/persistent/Persistent.java index bc5fd1ed7..31159955d 100644 --- a/VelocityCore/Persistent/src/de/steamwar/persistent/Persistent.java +++ b/VelocityCore/Persistent/src/de/steamwar/persistent/Persistent.java @@ -24,9 +24,11 @@ import com.google.inject.Inject; import com.google.inject.Module; import com.google.inject.name.Names; import com.mojang.brigadier.Command; +import com.mojang.brigadier.context.CommandContext; import com.velocitypowered.api.command.BrigadierCommand; import com.velocitypowered.api.command.CommandManager; import com.velocitypowered.api.command.CommandMeta; +import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.event.EventManager; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; @@ -71,12 +73,20 @@ public class Persistent { private final Logger logger; private final Path directory; + private boolean restartQueued = false; + @Inject public Persistent(ProxyServer proxy, Logger logger, @DataDirectory Path dataDirectory) { instance = this; this.proxy = proxy; this.logger = logger; this.directory = dataDirectory; + + proxy.getScheduler().buildTask(instance, () -> { + if (!restartQueued) return; + if (!proxy.getAllPlayers().isEmpty()) return; + proxy.shutdown(); + }).repeat(10, TimeUnit.SECONDS).schedule(); } @Subscribe @@ -89,6 +99,14 @@ public class Persistent { .build() ) ); + proxy.getCommandManager().register( + new BrigadierCommand( + BrigadierCommand.literalArgumentBuilder("queuerestart") + .requires(commandSource -> commandSource.hasPermission("bungeecore.softreload")) + .executes(this::queueRestart) + .build() + ) + ); } @Subscribe @@ -97,6 +115,7 @@ public class Persistent { } public int softreload() { + restartQueued = false; PluginContainer container = null; ReloadablePlugin plugin = null; try { @@ -200,4 +219,10 @@ public class Persistent { ResourceBundle.clearCache(classLoader); classLoader.close(); } + + public int queueRestart(CommandContext context) { + restartQueued = true; + context.getSource().sendRichMessage("§eRestart queued§8."); + return Command.SINGLE_SUCCESS; + } } From c12d2c2ddfc4315ab929840ed13c3eafabe37a64 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Tue, 10 Jun 2025 20:39:11 +0200 Subject: [PATCH 034/153] Add player count to ListCommand --- VelocityCore/src/de/steamwar/messages/BungeeCore.properties | 2 +- VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties | 3 --- .../src/de/steamwar/velocitycore/commands/ListCommand.java | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties index c46cd3177..f1af8a923 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties @@ -602,7 +602,7 @@ TABLIST_PHASE_WEBSITE=§8Website: https://§eSteam§8War.de TABLIST_PHASE_DISCORD=§8Discord: https://§eSteam§8War.de/discord TABLIST_FOOTER=§e{0} {1}§8ms §ePlayers§8: §7{2} TABLIST_BAU=§7§lBuild -LIST_COMMAND=§e{0}§8: §7{1} +LIST_COMMAND=§e{0}§8 [{1}]: §7{2} #EventStarter EVENT_FIGHT_BROADCAST=§eClick here §7for the fight §{0}{1} §8vs §{2}{3} diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties index 51a47cc3d..bc465945e 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties @@ -573,11 +573,8 @@ POLL_ANSWER=§7{0} POLL_ANSWER_HOVER=§e{0} §ewählen #TablistManager -TABLIST_PHASE_WEBSITE=§8Website: https://§eSteam§8War.de -TABLIST_PHASE_DISCORD=§8Discord: https://§eSteam§8War.de/discord TABLIST_FOOTER=§e{0} {1}§8ms §eSpieler§8: §7{2} TABLIST_BAU=§7§lBau -LIST_COMMAND=§e{0}§8: §7{1} #EventStarter EVENT_FIGHT_BROADCAST=§7Hier §eklicken §7für den Kampf §{0}{1} §8vs §{2}{3} diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/ListCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/ListCommand.java index 1505b4388..dab59005c 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/ListCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/ListCommand.java @@ -63,7 +63,7 @@ public class ListCommand extends SWCommand { if (server.equals("Bau")) { serverName = sender.parseToLegacy("TABLIST_BAU"); } - sender.prefixless("LIST_COMMAND", serverName, playerMap.get(server).stream().map(Player::getUsername).collect(Collectors.joining(", "))); + sender.prefixless("LIST_COMMAND", serverName, playerMap.get(server).size(), playerMap.get(server).stream().map(Player::getUsername).collect(Collectors.joining(", "))); } } } From adaae7f9435bbaf326c3e43a8440e31d012e00d4 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Tue, 10 Jun 2025 20:40:04 +0200 Subject: [PATCH 035/153] Update Persistent.queueRestart to toggle --- .../src/de/steamwar/persistent/Persistent.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/VelocityCore/Persistent/src/de/steamwar/persistent/Persistent.java b/VelocityCore/Persistent/src/de/steamwar/persistent/Persistent.java index 31159955d..9415574bd 100644 --- a/VelocityCore/Persistent/src/de/steamwar/persistent/Persistent.java +++ b/VelocityCore/Persistent/src/de/steamwar/persistent/Persistent.java @@ -221,8 +221,13 @@ public class Persistent { } public int queueRestart(CommandContext context) { - restartQueued = true; - context.getSource().sendRichMessage("§eRestart queued§8."); + if (restartQueued) { + restartQueued = false; + context.getSource().sendRichMessage("§eRestart dequeued§8."); + } else { + restartQueued = true; + context.getSource().sendRichMessage("§eRestart queued§8."); + } return Command.SINGLE_SUCCESS; } } From 1aba92e70758b30d173475e47518cac7885e10b8 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 10 Jun 2025 22:29:31 +0200 Subject: [PATCH 036/153] Add `seen` and `nodeType` fields to CheckedSchematic class --- CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java b/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java index 0037d8805..a0d52e4f9 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java +++ b/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java @@ -75,8 +75,10 @@ public class CheckedSchematic { @Field private final String declineReason; @Getter + @Field private boolean seen; @Getter + @Field private final String nodeType; public int getNode() { From 38559e8a2b151111477225f8d8e6d874a1ccff14 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 10 Jun 2025 22:31:14 +0200 Subject: [PATCH 037/153] Fix parameter order in CheckedSchematic.create method --- CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java b/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java index a0d52e4f9..d1b809f33 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java +++ b/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java @@ -41,7 +41,7 @@ public class CheckedSchematic { private static final Statement updateSeen = new Statement("UPDATE CheckedSchematic SET Seen = ? WHERE StartTime = ? AND EndTime = ? AND NodeName = ?"); public static void create(SchematicNode node, int validator, Timestamp startTime, Timestamp endTime, String reason, boolean seen) { - insert.update(node.getId(), node.getName(), node.getOwner(), validator, startTime, endTime, reason, seen, node.getSchemtype().toDB()); + insert.update(node.getId(), node.getOwner(), node.getName(), validator, startTime, endTime, reason, seen, node.getSchemtype().toDB()); } public static List getLastDeclinedOfNode(int node) { From ecb2e736aa58645f78e0ba8a0bce27c6e246fac5 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 10 Jun 2025 22:34:27 +0200 Subject: [PATCH 038/153] Mark declined schematics as seen and fix substring usage in CheckedSchematic creation --- CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java | 2 +- .../de/steamwar/velocitycore/listeners/ConnectionListener.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java b/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java index d1b809f33..59ed8d2f6 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java +++ b/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java @@ -41,7 +41,7 @@ public class CheckedSchematic { private static final Statement updateSeen = new Statement("UPDATE CheckedSchematic SET Seen = ? WHERE StartTime = ? AND EndTime = ? AND NodeName = ?"); public static void create(SchematicNode node, int validator, Timestamp startTime, Timestamp endTime, String reason, boolean seen) { - insert.update(node.getId(), node.getOwner(), node.getName(), validator, startTime, endTime, reason, seen, node.getSchemtype().toDB()); + insert.update(node.getId(), node.getOwner(), node.getName(), validator, startTime, endTime, reason, seen, node.getSchemtype().toDB().substring(1)); } public static List getLastDeclinedOfNode(int node) { diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java index c0efc3a28..a6d879c13 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java @@ -94,6 +94,8 @@ public class ConnectionListener extends BasicListener { } else { chatter.system("CHECK_DECLINED", type.name(), checkedSchematic.getSchemName(), checkedSchematic.getDeclineReason()); } + + checkedSchematic.setSeen(true); } if(newPlayers.contains(player.getUniqueId())){ From 26b126fdba1c22e39cda46898cf75724794c08ba Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 11 Jun 2025 08:05:28 +0200 Subject: [PATCH 039/153] Hotfix Persistent --- .../Persistent/src/de/steamwar/persistent/Persistent.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/VelocityCore/Persistent/src/de/steamwar/persistent/Persistent.java b/VelocityCore/Persistent/src/de/steamwar/persistent/Persistent.java index 9415574bd..8c6f47b82 100644 --- a/VelocityCore/Persistent/src/de/steamwar/persistent/Persistent.java +++ b/VelocityCore/Persistent/src/de/steamwar/persistent/Persistent.java @@ -81,16 +81,16 @@ public class Persistent { this.proxy = proxy; this.logger = logger; this.directory = dataDirectory; + } + @Subscribe + public void onEnable(ProxyInitializeEvent event) { proxy.getScheduler().buildTask(instance, () -> { if (!restartQueued) return; if (!proxy.getAllPlayers().isEmpty()) return; proxy.shutdown(); }).repeat(10, TimeUnit.SECONDS).schedule(); - } - @Subscribe - public void onEnable(ProxyInitializeEvent event) { proxy.getCommandManager().register( new BrigadierCommand( BrigadierCommand.literalArgumentBuilder("softreload") From 909c1c52aaf4b9bb3d2ee093df3d82c66831d1b9 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 11 Jun 2025 08:09:31 +0200 Subject: [PATCH 040/153] Hotfix Persistent --- .../Persistent/src/de/steamwar/persistent/Persistent.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VelocityCore/Persistent/src/de/steamwar/persistent/Persistent.java b/VelocityCore/Persistent/src/de/steamwar/persistent/Persistent.java index 8c6f47b82..52f764f27 100644 --- a/VelocityCore/Persistent/src/de/steamwar/persistent/Persistent.java +++ b/VelocityCore/Persistent/src/de/steamwar/persistent/Persistent.java @@ -223,10 +223,10 @@ public class Persistent { public int queueRestart(CommandContext context) { if (restartQueued) { restartQueued = false; - context.getSource().sendRichMessage("§eRestart dequeued§8."); + context.getSource().sendPlainMessage("§eRestart dequeued§8."); } else { restartQueued = true; - context.getSource().sendRichMessage("§eRestart queued§8."); + context.getSource().sendPlainMessage("§eRestart queued§8."); } return Command.SINGLE_SUCCESS; } From 88d8016987674a8e1a67f661d37169ed006fbd62 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 11 Jun 2025 10:58:01 +0200 Subject: [PATCH 041/153] Fix TexturePackSystem --- .../listeners/TexturePackSystem.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/TexturePackSystem.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/TexturePackSystem.java index 46da12daf..c43c54b2d 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/TexturePackSystem.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/TexturePackSystem.java @@ -42,17 +42,16 @@ public class TexturePackSystem extends BasicListener { public TexturePackSystem() { // https://minecraft.wiki/w/Pack_format#List_of_resource_pack_formats // https://minecraft.wiki/w/Minecraft_Wiki:Projects/wiki.vg_merge/Protocol_version_numbers - protocolVersionToPackVersion.put(759, 9); - protocolVersionToPackVersion.put(761, 12); - protocolVersionToPackVersion.put(762, 13); + protocolVersionToPackVersion.put(759, 10); + protocolVersionToPackVersion.put(762, 12); protocolVersionToPackVersion.put(763, 15); protocolVersionToPackVersion.put(764, 18); - protocolVersionToPackVersion.put(765, 22); - protocolVersionToPackVersion.put(766, 32); - protocolVersionToPackVersion.put(767, 34); - protocolVersionToPackVersion.put(768, 42); - protocolVersionToPackVersion.put(769, 46); - protocolVersionToPackVersion.put(770, 55); + protocolVersionToPackVersion.put(765, 26); + protocolVersionToPackVersion.put(766, 41); + protocolVersionToPackVersion.put(767, 48); + protocolVersionToPackVersion.put(768, 57); + protocolVersionToPackVersion.put(769, 61); + protocolVersionToPackVersion.put(770, 71); } @Subscribe From 0ea92be2e1eb6dcc9b7527bb6c3a3e1cd0df7610 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 11 Jun 2025 11:25:56 +0200 Subject: [PATCH 042/153] Fix TexturePackSystem --- .../listeners/TexturePackSystem.java | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/TexturePackSystem.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/TexturePackSystem.java index c43c54b2d..cebe9d6d2 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/TexturePackSystem.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/TexturePackSystem.java @@ -42,16 +42,16 @@ public class TexturePackSystem extends BasicListener { public TexturePackSystem() { // https://minecraft.wiki/w/Pack_format#List_of_resource_pack_formats // https://minecraft.wiki/w/Minecraft_Wiki:Projects/wiki.vg_merge/Protocol_version_numbers - protocolVersionToPackVersion.put(759, 10); - protocolVersionToPackVersion.put(762, 12); - protocolVersionToPackVersion.put(763, 15); - protocolVersionToPackVersion.put(764, 18); - protocolVersionToPackVersion.put(765, 26); - protocolVersionToPackVersion.put(766, 41); - protocolVersionToPackVersion.put(767, 48); - protocolVersionToPackVersion.put(768, 57); - protocolVersionToPackVersion.put(769, 61); - protocolVersionToPackVersion.put(770, 71); + protocolVersionToPackVersion.put(759, 10); // 1.19 - 1.19.3 + protocolVersionToPackVersion.put(762, 12); // 1.19.4 + protocolVersionToPackVersion.put(763, 15); // 1.20 - 1.20.1 + protocolVersionToPackVersion.put(764, 18); // 1.20.2 + protocolVersionToPackVersion.put(765, 26); // 1.20.3 - 1.20.4 + protocolVersionToPackVersion.put(766, 41); // 1.20.5 - 1.20.6 + protocolVersionToPackVersion.put(767, 48); // 1.21 - 1.21.1 + protocolVersionToPackVersion.put(768, 57); // 1.21.2 - 1.21.3 + protocolVersionToPackVersion.put(769, 61); // 1.21.4 + protocolVersionToPackVersion.put(770, 71); // 1.21.5 } @Subscribe @@ -60,22 +60,23 @@ public class TexturePackSystem extends BasicListener { return; } VelocityCore.schedule(() -> { - int playerVersion = event.getPlayer().getProtocolVersion().getProtocol(); - File selectedPack = null; - while (selectedPack == null) { - Map.Entry pack = protocolVersionToPackVersion.floorEntry(playerVersion); - if (pack == null) return; - - for (File file : PACKS_DIR.listFiles()) { - if (file.getName().startsWith(pack.getValue() + "_")) { - selectedPack = file; - break; - } + TreeMap fileTreeMap = new TreeMap<>(); + for (File fileEntry : PACKS_DIR.listFiles()) { + try { + int packVersion = Integer.parseInt(fileEntry.getName().split("_")[0]); + fileTreeMap.put(packVersion, fileEntry); + } catch (NumberFormatException e) { + // Ignore } - - playerVersion--; } + int playerVersion = event.getPlayer().getProtocolVersion().getProtocol(); + Map.Entry packVersionEntry = protocolVersionToPackVersion.floorEntry(playerVersion); + if (packVersionEntry == null) return; + Map.Entry selectedPackEntry = fileTreeMap.floorEntry(packVersionEntry.getValue()); + if (selectedPackEntry == null) return; + File selectedPack = selectedPackEntry.getValue(); + String fileName = selectedPack.getName(); fileName = fileName.substring(fileName.indexOf('_') + 1, fileName.lastIndexOf('.')); byte[] hash = hexStringToByteArray(fileName); From 24f4ab7f37685f06f34b19bb0b55c54c4685e3b2 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 11 Jun 2025 15:35:27 +0200 Subject: [PATCH 043/153] Fix RPlayer not showing when same player is present Add DevLobby20 to LobbySystem build.gradle.kts --- LobbySystem/build.gradle.kts | 9 ++ .../src/de/steamwar/entity/RPlayer.java | 83 ++++++++++++++++++- 2 files changed, 88 insertions(+), 4 deletions(-) diff --git a/LobbySystem/build.gradle.kts b/LobbySystem/build.gradle.kts index aa511a0cd..8662545cc 100644 --- a/LobbySystem/build.gradle.kts +++ b/LobbySystem/build.gradle.kts @@ -34,3 +34,12 @@ dependencies { compileOnly(libs.nms20) compileOnly(libs.worldedit15) } + +tasks.register("DevLobby20") { + group = "run" + description = "Run a 1.20 Dev Lobby" + dependsOn(":SpigotCore:shadowJar") + dependsOn(":LobbySystem:jar") + template = "Lobby20" + worldName = "Lobby" +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java index b4aaa3ee8..6205f5a68 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java @@ -19,22 +19,38 @@ package de.steamwar.entity; -import de.steamwar.Reflection; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; +import de.steamwar.Reflection; import de.steamwar.core.BountifulWrapper; import de.steamwar.core.Core; import de.steamwar.core.FlatteningWrapper; import de.steamwar.core.ProtocolWrapper; import lombok.Getter; +import lombok.SneakyThrows; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import java.util.UUID; import java.util.function.Consumer; import java.util.function.Function; +import java.util.stream.Collectors; @Getter public class RPlayer extends REntity { @@ -61,17 +77,76 @@ public class RPlayer extends REntity { private static final Object skinPartsDataWatcher = BountifulWrapper.impl.getDataWatcherObject(skinPartsIndex(), Byte.class); + private final UUID actualUUID; private final String name; public RPlayer(REntityServer server, UUID uuid, String name, Location location) { - super(server, EntityType.PLAYER, uuid, location,0); + super(server, EntityType.PLAYER, UUID.randomUUID(), location,0); + this.actualUUID = uuid; this.name = name; server.addEntity(this); } + private static final Map skinData = new LinkedHashMap() { + @Override + protected boolean removeEldestEntry(Map.Entry eldest) { + return size() > 100; + } + }; + + @SneakyThrows + public static Property fetchSkinData(UUID uuid) { + if (skinData.containsKey(uuid)) { + return skinData.get(uuid); + } + + String url = "https://sessionserver.mojang.com/session/minecraft/profile/" + uuid.toString().replace("-", "") + "?unsigned=false"; + + HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); + connection.setReadTimeout(5000); + connection.setConnectTimeout(5000); + connection.setRequestProperty("User-Agent", "SkinFetcher"); + + if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { + return null; + } + + InputStream is = connection.getInputStream(); + String json = new BufferedReader(new InputStreamReader(is)) + .lines().collect(Collectors.joining("\n")); + + JsonObject obj = JsonParser.parseString(json).getAsJsonObject(); + JsonArray properties = obj.getAsJsonArray("properties"); + for (JsonElement propElement : properties) { + JsonObject prop = propElement.getAsJsonObject(); + if (prop.get("name").getAsString().equals("textures")) { + Property property = new Property( + prop.get("name").getAsString(), + prop.get("value").getAsString(), + prop.get("signature").getAsString() + ); + skinData.put(uuid, property); + return property; + } + } + + throw new IOException("Failed to fetch skin profile"); + } + + private GameProfile getGameProfile() { + Property property = fetchSkinData(actualUUID); + if (property != null) { + GameProfile gameProfile = new GameProfile(uuid, name); + gameProfile.getProperties().put("textures", property); + return gameProfile; + } else { + return new GameProfile(actualUUID, name); + } + } + @Override void list(Consumer packetSink) { - packetSink.accept(ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.ADD, new GameProfile(uuid, name), GameMode.CREATIVE)); + packetSink.accept(ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.ADD, getGameProfile(), GameMode.CREATIVE)); } @Override @@ -88,7 +163,7 @@ public class RPlayer extends REntity { @Override void delist(Consumer packetSink) { - packetSink.accept(ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.REMOVE, new GameProfile(uuid, name), GameMode.CREATIVE)); + packetSink.accept(ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.REMOVE, getGameProfile(), GameMode.CREATIVE)); } private static final Class namedSpawnPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundAddPlayerPacket"); From 3d562cf74394b43696b69719f0416ff31e30a432 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 11 Jun 2025 17:05:47 +0200 Subject: [PATCH 044/153] Add skin cache to VelocityCore --- .../common/PlayerSkinRequestPacket.java | 36 +++++ .../common/PlayerSkinResponsePacket.java | 38 ++++++ .../src/de/steamwar/core/Promise.java | 47 +++++++ .../src/de/steamwar/entity/RPlayer.java | 70 ++-------- .../steamwar/network/CoreNetworkHandler.java | 11 ++ .../de/steamwar/network/NetworkSender.java | 43 +++++- .../steamwar/velocitycore/VelocityCore.java | 2 +- .../network/handlers/PlayerSkinHandler.java | 125 ++++++++++++++++++ 8 files changed, 310 insertions(+), 62 deletions(-) create mode 100644 CommonCore/Network/src/de/steamwar/network/packets/common/PlayerSkinRequestPacket.java create mode 100644 CommonCore/Network/src/de/steamwar/network/packets/common/PlayerSkinResponsePacket.java create mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/core/Promise.java create mode 100644 VelocityCore/src/de/steamwar/velocitycore/network/handlers/PlayerSkinHandler.java diff --git a/CommonCore/Network/src/de/steamwar/network/packets/common/PlayerSkinRequestPacket.java b/CommonCore/Network/src/de/steamwar/network/packets/common/PlayerSkinRequestPacket.java new file mode 100644 index 000000000..4916e0f1b --- /dev/null +++ b/CommonCore/Network/src/de/steamwar/network/packets/common/PlayerSkinRequestPacket.java @@ -0,0 +1,36 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.network.packets.common; + +import de.steamwar.network.packets.NetworkPacket; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.ToString; + +import java.util.UUID; + +@AllArgsConstructor +@Getter +@ToString +public class PlayerSkinRequestPacket extends NetworkPacket { + + private static final long serialVersionUID = 277267302555671765L; + private UUID uuid; +} diff --git a/CommonCore/Network/src/de/steamwar/network/packets/common/PlayerSkinResponsePacket.java b/CommonCore/Network/src/de/steamwar/network/packets/common/PlayerSkinResponsePacket.java new file mode 100644 index 000000000..5c3767caf --- /dev/null +++ b/CommonCore/Network/src/de/steamwar/network/packets/common/PlayerSkinResponsePacket.java @@ -0,0 +1,38 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.network.packets.common; + +import de.steamwar.network.packets.NetworkPacket; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.ToString; + +import java.util.UUID; + +@AllArgsConstructor +@Getter +@ToString +public class PlayerSkinResponsePacket extends NetworkPacket { + + private static final long serialVersionUID = 5792855362547625112L; + private UUID uuid; + private String skin; + private String signature; +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Promise.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Promise.java new file mode 100644 index 000000000..393932f33 --- /dev/null +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Promise.java @@ -0,0 +1,47 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.core; + +import lombok.NoArgsConstructor; + +import java.util.concurrent.atomic.AtomicBoolean; + +@NoArgsConstructor +public class Promise { + + private AtomicBoolean hasValue = new AtomicBoolean(false); + private E value; + + public void setValue(E value) { + this.value = value; + hasValue.set(true); + } + + public E getValue() { + if (hasValue.get()) { + return value; + } + + while (hasValue.get()) { + Thread.yield(); + } + return value; + } +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java index 6205f5a68..5efdd3f9d 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java @@ -19,38 +19,23 @@ package de.steamwar.entity; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import de.steamwar.Reflection; -import de.steamwar.core.BountifulWrapper; -import de.steamwar.core.Core; -import de.steamwar.core.FlatteningWrapper; -import de.steamwar.core.ProtocolWrapper; +import de.steamwar.core.*; +import de.steamwar.network.NetworkSender; +import de.steamwar.network.packets.common.PlayerSkinRequestPacket; import lombok.Getter; -import lombok.SneakyThrows; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.UUID; import java.util.function.Consumer; import java.util.function.Function; -import java.util.stream.Collectors; @Getter public class RPlayer extends REntity { @@ -87,54 +72,19 @@ public class RPlayer extends REntity { server.addEntity(this); } - private static final Map skinData = new LinkedHashMap() { + public static final Map> SKIN_DATA_PROMISES = new LinkedHashMap>() { @Override - protected boolean removeEldestEntry(Map.Entry eldest) { + protected boolean removeEldestEntry(Map.Entry> eldest) { return size() > 100; } }; - @SneakyThrows - public static Property fetchSkinData(UUID uuid) { - if (skinData.containsKey(uuid)) { - return skinData.get(uuid); - } - - String url = "https://sessionserver.mojang.com/session/minecraft/profile/" + uuid.toString().replace("-", "") + "?unsigned=false"; - - HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); - connection.setReadTimeout(5000); - connection.setConnectTimeout(5000); - connection.setRequestProperty("User-Agent", "SkinFetcher"); - - if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { - return null; - } - - InputStream is = connection.getInputStream(); - String json = new BufferedReader(new InputStreamReader(is)) - .lines().collect(Collectors.joining("\n")); - - JsonObject obj = JsonParser.parseString(json).getAsJsonObject(); - JsonArray properties = obj.getAsJsonArray("properties"); - for (JsonElement propElement : properties) { - JsonObject prop = propElement.getAsJsonObject(); - if (prop.get("name").getAsString().equals("textures")) { - Property property = new Property( - prop.get("name").getAsString(), - prop.get("value").getAsString(), - prop.get("signature").getAsString() - ); - skinData.put(uuid, property); - return property; - } - } - - throw new IOException("Failed to fetch skin profile"); - } - private GameProfile getGameProfile() { - Property property = fetchSkinData(actualUUID); + Property property = SKIN_DATA_PROMISES.computeIfAbsent(uuid, __ -> { + Promise future = new Promise<>(); + NetworkSender.sendOrQueue(new PlayerSkinRequestPacket(uuid)); + return future; + }).getValue(); if (property != null) { GameProfile gameProfile = new GameProfile(uuid, name); gameProfile.getProperties().put("textures", property); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/network/CoreNetworkHandler.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/network/CoreNetworkHandler.java index bf74682a6..407e9e414 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/network/CoreNetworkHandler.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/network/CoreNetworkHandler.java @@ -19,9 +19,13 @@ package de.steamwar.network; +import com.mojang.authlib.properties.Property; import de.steamwar.core.BountifulWrapper; +import de.steamwar.core.Promise; +import de.steamwar.entity.RPlayer; import de.steamwar.network.handlers.InventoryHandler; import de.steamwar.network.packets.PacketHandler; +import de.steamwar.network.packets.common.PlayerSkinResponsePacket; import de.steamwar.network.packets.server.*; import de.steamwar.sql.BauweltMember; import de.steamwar.sql.SteamwarUser; @@ -68,4 +72,11 @@ public class CoreNetworkHandler extends PacketHandler { public void handleLocaleChange(LocaleInvalidationPacket packet) { SteamwarUser.invalidate(packet.getPlayerId()); } + + @Handler + public void handlePlayerSkinResponse(PlayerSkinResponsePacket packet) { + Promise propertyPromise = RPlayer.SKIN_DATA_PROMISES.get(packet.getUuid()); + if (propertyPromise == null) return; + propertyPromise.setValue(new Property("textures", packet.getSkin(), packet.getSignature())); + } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/network/NetworkSender.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/network/NetworkSender.java index 10a387d87..2dda8b929 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/network/NetworkSender.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/network/NetworkSender.java @@ -24,8 +24,49 @@ import de.steamwar.network.packets.NetworkPacket; import lombok.SneakyThrows; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; -public class NetworkSender { +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; + +public class NetworkSender implements Listener { + + private static AtomicInteger numberOfPlayers = new AtomicInteger(0); + private static List queued = new ArrayList<>(); + + static { + Bukkit.getPluginManager().registerEvents(new NetworkSender(), Core.getInstance()); + } + + private NetworkSender() { + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + numberOfPlayers.incrementAndGet(); + if (numberOfPlayers.get() > 1) return; + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { + queued.forEach(NetworkSender::send); + queued.clear(); + }, 1); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + numberOfPlayers.decrementAndGet(); + } + + public static void sendOrQueue(NetworkPacket packet) { + if (numberOfPlayers.get() > 0) { + send(packet); + } else { + queued.add(packet); + } + } public static void send(NetworkPacket packet) { Bukkit.getOnlinePlayers().stream().findAny().ifPresent(player -> send(packet, player)); diff --git a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java index 517d33429..841b657d7 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java +++ b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java @@ -225,7 +225,7 @@ public class VelocityCore implements ReloadablePlugin { for(PacketHandler handler : new PacketHandler[] { new EloPlayerHandler(), new EloSchemHandler(), new ExecuteCommandHandler(), new FightInfoHandler(), - new ImALobbyHandler(), new InventoryCallbackHandler(), new PrepareSchemHandler() + new ImALobbyHandler(), new InventoryCallbackHandler(), new PrepareSchemHandler(), new PlayerSkinHandler() }) handler.register(); diff --git a/VelocityCore/src/de/steamwar/velocitycore/network/handlers/PlayerSkinHandler.java b/VelocityCore/src/de/steamwar/velocitycore/network/handlers/PlayerSkinHandler.java new file mode 100644 index 000000000..0baf15ba3 --- /dev/null +++ b/VelocityCore/src/de/steamwar/velocitycore/network/handlers/PlayerSkinHandler.java @@ -0,0 +1,125 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.velocitycore.network.handlers; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.connection.PostLoginEvent; +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.util.GameProfile; +import de.steamwar.network.packets.PacketHandler; +import de.steamwar.network.packets.common.PlayerSkinRequestPacket; +import de.steamwar.network.packets.common.PlayerSkinResponsePacket; +import de.steamwar.persistent.Storage; +import de.steamwar.velocitycore.VelocityCore; +import de.steamwar.velocitycore.network.NetworkSender; +import de.steamwar.velocitycore.network.ServerMetaInfo; +import lombok.SneakyThrows; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.stream.Collectors; + +public class PlayerSkinHandler extends PacketHandler { + + private final int maxCacheSize = 1000; + + public PlayerSkinHandler() { + VelocityCore.getProxy().getEventManager().register(VelocityCore.get(), this); + } + + private Map skins = new LinkedHashMap<>() { + @Override + protected boolean removeEldestEntry(Map.Entry eldest) { + return size() > maxCacheSize; + } + }; + private Map signatures = new LinkedHashMap<>() { + @Override + protected boolean removeEldestEntry(Map.Entry eldest) { + return size() > maxCacheSize; + } + }; + + @Handler + @SneakyThrows + public void handle(PlayerSkinRequestPacket packet) { + if (skins.containsKey(packet.getUuid()) && signatures.containsKey(packet.getUuid())) { + NetworkSender.send(((ServerMetaInfo) packet.getMetaInfos()).sender().getServer(), new PlayerSkinResponsePacket(packet.getUuid(), skins.get(packet.getUuid()), signatures.get(packet.getUuid()))); + return; + } + + String url = "https://sessionserver.mojang.com/session/minecraft/profile/" + packet.getUuid().toString().replace("-", "") + "?unsigned=false"; + + HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); + connection.setReadTimeout(5000); + connection.setConnectTimeout(5000); + connection.setRequestProperty("User-Agent", "SkinFetcher"); + + if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { + return; + } + + InputStream is = connection.getInputStream(); + String json = new BufferedReader(new InputStreamReader(is)) + .lines().collect(Collectors.joining("\n")); + + JsonObject obj = JsonParser.parseString(json).getAsJsonObject(); + JsonArray properties = obj.getAsJsonArray("properties"); + for (JsonElement propElement : properties) { + JsonObject prop = propElement.getAsJsonObject(); + if (prop.get("name").getAsString().equals("textures")) { + String skin = prop.get("value").getAsString(); + String signature = prop.get("signature").getAsString(); + skins.put(packet.getUuid(), skin); + signatures.put(packet.getUuid(), signature); + NetworkSender.send(((ServerMetaInfo) packet.getMetaInfos()).sender().getServer(), new PlayerSkinResponsePacket(packet.getUuid(), skin, signature)); + return; + } + } + } + + @Subscribe + public void onPostLogin(PostLoginEvent event) { + Player player = event.getPlayer(); + GameProfile gameProfile = player.getGameProfile(); + GameProfile.Property property = gameProfile.getProperties().stream().filter(p -> p.getName().equals("textures")).findFirst().orElse(null); + if (property == null) return; + skins.put(player.getUniqueId(), property.getValue()); + signatures.put(player.getUniqueId(), property.getSignature()); + + Set uuidSet = skins.keySet(); + VelocityCore.getProxy().getAllServers().forEach(server -> { + for (UUID uuid : uuidSet) { + NetworkSender.send(server, new PlayerSkinResponsePacket(uuid, skins.get(uuid), signatures.get(uuid))); + } + }); + } +} From 3296d9ebb378cb1af4f05284151c982be6caee2b Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 12 Jun 2025 18:53:35 +0200 Subject: [PATCH 045/153] Add CEntity, CLine, CWireframe and optimize REntityServer --- .../src/de/steamwar/entity/CEntity.java | 67 +++++ .../src/de/steamwar/entity/CLine.java | 244 ++++++++++++++++++ .../src/de/steamwar/entity/CWireframe.java | 103 ++++++++ .../src/de/steamwar/entity/REntityServer.java | 6 +- 4 files changed, 416 insertions(+), 4 deletions(-) create mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CEntity.java create mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CLine.java create mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CWireframe.java diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CEntity.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CEntity.java new file mode 100644 index 000000000..373a2acf2 --- /dev/null +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CEntity.java @@ -0,0 +1,67 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.entity; + +import org.bukkit.Location; +import org.bukkit.entity.EntityType; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * CEntities are Entities that are a compound of other Entities. + */ +public class CEntity extends REntity { + + protected List entities = new ArrayList<>(); + + public CEntity(REntityServer server) { + super(server, EntityType.MARKER, new Location(null, 0, 0, 0)); + } + + public List getEntities() { + return new ArrayList<>(entities); + } + + public List getEntitiesByType(Class clazz) { + return entities.stream().filter(clazz::isInstance).map(clazz::cast).collect(Collectors.toList()); + } + + @Override + void tick() { + entities.forEach(REntity::tick); + } + + @Override + public void hide(boolean hide) { + super.hide(hide); + entities.forEach(rEntity -> { + rEntity.hide(hide); + }); + } + + @Override + public void die() { + super.die(); + entities.forEach(REntity::die); + entities.clear(); + } +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CLine.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CLine.java new file mode 100644 index 000000000..e145bb607 --- /dev/null +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CLine.java @@ -0,0 +1,244 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.entity; + +import org.bukkit.Location; +import org.bukkit.block.data.BlockData; +import org.bukkit.entity.Display; +import org.bukkit.entity.Player; +import org.bukkit.util.Consumer; +import org.bukkit.util.Transformation; +import org.bukkit.util.Vector; +import org.joml.Quaternionf; +import org.joml.Vector3f; + +import java.util.Objects; + +public class CLine extends CEntity { + + public static final float DEFAULT_WIDTH = 1 / 16f; + private static final float offset = 1 / 1024f; + private static final Vector offsetVec = new Vector(offset, offset, offset); + + private Location from; + private Location to; + private float width = DEFAULT_WIDTH; + private BlockData blockData = RBlockDisplay.DEFAULT_BLOCK; + + public CLine(REntityServer server) { + super(server); + } + + private CLine checkAndSet(T currentValue, T newValue, Consumer setter) { + if (Objects.equals(currentValue, newValue)) return this; + setter.accept(newValue); + tick(); + return this; + } + + public CLine setFrom(Location from) { + return checkAndSet(this.from, from, location -> this.from = location); + } + + public CLine setTo(Location to) { + return checkAndSet(this.to, to, location -> this.to = location); + } + + public CLine setWidth(float width) { + return checkAndSet(this.width, width, w -> this.width = w); + } + + public CLine setBlock(BlockData blockData) { + if (this.blockData.equals(blockData)) return this; + if (blockData == null) { + this.blockData = RBlockDisplay.DEFAULT_BLOCK; + } else { + this.blockData = blockData; + } + getEntitiesByType(RBlockDisplay.class).forEach(display -> { + display.setBlock(blockData); + }); + return this; + } + + private boolean hide = false; + + @Override + public void hide(boolean hide) { + if (hide == this.hide) return; + this.hide = hide; + if (hide) { + if (startLine != null) startLine.hide(true); + if (middleLine != null) middleLine.hide(true); + if (endLine != null) endLine.hide(true); + } else { + tick(); + } + } + + @Override + void tick() { + if (from == null || to == null) return; + if (hide) return; + updateStart(); + updateMiddle(); + updateEnd(); + } + + private RBlockDisplay startLine; + private void updateStart() { + Vector vec = to.clone().subtract(from).toVector(); + if (vec.length() > 35) vec.normalize().multiply(35); + + if (startLine == null) { + startLine = new RBlockDisplay(server, new Location(null, 0, 0, 0)); + startLine.setBrightness(new Display.Brightness(15, 15)); + startLine.setViewRange(560); + startLine.setBlock(blockData); + entities.add(startLine); + } else { + startLine.hide(false); + } + + startLine.move(from.clone().subtract(offsetVec)); + startLine.setTransform(new Transformation(new Vector3f(0, 0, 0), new Quaternionf(0, 0, 0, 1), addWidth(vec).toVector3f(), new Quaternionf(0, 0, 0, 1))); + } + + private RBlockDisplay middleLine; + private void updateMiddle() { + Vector vec = to.clone().subtract(from).toVector(); + if (vec.length() <= 70) { + if (middleLine != null) middleLine.hide(true); + return; + } + if (vec.length() > 280) vec.normalize().multiply(280); + else vec = vec.clone().normalize().multiply(vec.length() - 60); + + if (middleLine == null) { + middleLine = new RBlockDisplay(server, new Location(null, 0, 0, 0)); + middleLine.setBrightness(new Display.Brightness(15, 15)); + middleLine.setViewRange(560); + middleLine.setBlock(blockData); + entities.add(middleLine); + } else { + middleLine.hide(false); + } + + Player player = server.getPlayers().stream().findFirst().orElse(null); + if (player == null) return; + + Vector tempVector = vec.clone().normalize().multiply(30); + Location from = this.from.clone().add(tempVector); + Location to = this.to.clone().subtract(tempVector); + + Vector lineVec = to.clone().subtract(from).toVector(); + Vector playerVec = player.getLocation().toVector().subtract(from.toVector()); + double lineVecDotItself = lineVec.dot(lineVec); + Vector projectionVec = lineVec.clone().multiply(lineVec.dot(playerVec)).divide(new Vector(lineVecDotItself, lineVecDotItself, lineVecDotItself)); + + Vector moveVec = from.toVector().add(projectionVec); + if (moveVec.getX() < from.getX()) { + moveVec.setX(from.getX()); + } + if (moveVec.getX() > to.getX()) { + moveVec.setX(to.getX()); + } + if (moveVec.getY() < from.getY()) { + moveVec.setY(from.getY()); + } + if (moveVec.getY() > to.getY()) { + moveVec.setY(to.getY()); + } + if (moveVec.getZ() < from.getZ()) { + moveVec.setZ(from.getZ()); + } + if (moveVec.getZ() > to.getZ()) { + moveVec.setZ(to.getZ()); + } + + Vector translation = vec.clone().divide(new Vector(2, 2, 2)); + translation.setX(-translation.getX()); + translation.setY(-translation.getY()); + translation.setZ(-translation.getZ()); + + Vector first = moveVec.clone().add(translation).subtract(from.toVector()); + if (first.getX() < 0) { + translation.setX(translation.getX() - first.getX()); + } + if (first.getY() < 0) { + translation.setY(translation.getY() - first.getY()); + } + if (first.getZ() < 0) { + translation.setZ(translation.getZ() - first.getZ()); + } + + Vector second = to.toVector().subtract(moveVec.clone().subtract(translation)); + if (second.getX() < 0) { + translation.setX(translation.getX() + second.getX()); + } + if (second.getY() < 0) { + translation.setY(translation.getY() + second.getY()); + } + if (second.getZ() < 0) { + translation.setZ(translation.getZ() + second.getZ()); + } + + middleLine.move(moveVec.toLocation(player.getWorld()).subtract(offsetVec)); + middleLine.setTransform(new Transformation(translation.toVector3f(), new Quaternionf(0, 0, 0, 1), addWidth(vec).toVector3f(), new Quaternionf(0, 0, 0, 1))); + } + + private RBlockDisplay endLine; + private void updateEnd() { + Vector vec = to.clone().subtract(from).toVector(); + if (vec.length() <= 35) { + if (endLine != null) endLine.hide(true); + return; + } + if (vec.length() > 35) vec.normalize().multiply(35); + + if (endLine == null) { + endLine = new RBlockDisplay(server, new Location(null, 0, 0, 0)); + endLine.setBrightness(new Display.Brightness(15, 15)); + endLine.setViewRange(560); + endLine.setBlock(blockData); + entities.add(endLine); + } else { + endLine.hide(false); + } + + endLine.move(to.clone().subtract(offsetVec)); + endLine.setTransform(new Transformation(vec.toVector3f().negate(), new Quaternionf(0, 0, 0, 1), addWidth(vec).toVector3f(), new Quaternionf(0, 0, 0, 1))); + } + + private Vector addWidth(Vector vector) { + vector = vector.clone(); + if (vector.getX() == 0) { + vector.setX(vector.getX() + width); + } + if (vector.getY() == 0) { + vector.setY(vector.getY() + width); + } + if (vector.getZ() == 0) { + vector.setZ(vector.getZ() + width); + } + vector.add(offsetVec).add(offsetVec); + return vector; + } +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CWireframe.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CWireframe.java new file mode 100644 index 000000000..cf15912da --- /dev/null +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CWireframe.java @@ -0,0 +1,103 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.entity; + +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.data.BlockData; +import org.bukkit.util.Consumer; +import org.bukkit.util.Vector; + +import java.util.List; +import java.util.Objects; + +/** + * Compound Box (12 CLine) + */ +public class CWireframe extends CEntity { + + public static final float DEFAULT_WIDTH = 1 / 16f; + private float width = DEFAULT_WIDTH; + + private Location pos1; + private Location pos2; + + public CWireframe(REntityServer server) { + super(server); + for (int i = 0; i < 12; i++) { + entities.add(new CLine(server)); + } + } + + public CWireframe setPos1(Location pos1) { + this.pos1 = pos1; + updateAndSpawnLines(); + return this; + } + + public CWireframe setPos2(Location pos2) { + this.pos2 = pos2; + updateAndSpawnLines(); + return this; + } + + public CWireframe setWidth(float width) { + this.width = width; + updateAndSpawnLines(); + getEntitiesByType(CLine.class).forEach(haaLine -> { + haaLine.setWidth(width); + }); + return this; + } + + public CWireframe setBlock(BlockData blockData) { + getEntitiesByType(CLine.class).forEach(haaLine -> { + haaLine.setBlock(blockData); + }); + return this; + } + + private void updateAndSpawnLines() { + if (pos1 == null || pos2 == null) return; + + World world = pos1.getWorld(); + Vector min = Vector.getMinimum(pos1.toVector(), pos2.toVector()); + Vector max = Vector.getMaximum(pos1.toVector(), pos2.toVector()) + .add(new Vector(1 - width, 1 - width, 1 - width)); + + List lines = getEntitiesByType(CLine.class); + lines.forEach(line -> line.setFrom(null).setTo(null)); + + lines.get(0).setFrom(new Vector(min.getX(), min.getY(), min.getZ()).toLocation(world)).setTo(new Vector(max.getX() + width, min.getY(), min.getZ()).toLocation(world)); + lines.get(1).setFrom(new Vector(min.getX(), max.getY(), min.getZ()).toLocation(world)).setTo(new Vector(max.getX() + width, max.getY(), min.getZ()).toLocation(world)); + lines.get(2).setFrom(new Vector(min.getX(), min.getY(), max.getZ()).toLocation(world)).setTo(new Vector(max.getX() + width, min.getY(), max.getZ()).toLocation(world)); + lines.get(3).setFrom(new Vector(min.getX(), max.getY(), max.getZ()).toLocation(world)).setTo(new Vector(max.getX() + width, max.getY(), max.getZ()).toLocation(world)); + + lines.get(4).setFrom(new Vector(min.getX(), min.getY(), min.getZ()).toLocation(world)).setTo(new Vector(min.getX(), max.getY() + width, min.getZ()).toLocation(world)); + lines.get(5).setFrom(new Vector(max.getX(), min.getY(), min.getZ()).toLocation(world)).setTo(new Vector(max.getX(), max.getY() + width, min.getZ()).toLocation(world)); + lines.get(6).setFrom(new Vector(min.getX(), min.getY(), max.getZ()).toLocation(world)).setTo(new Vector(min.getX(), max.getY() + width, max.getZ()).toLocation(world)); + lines.get(7).setFrom(new Vector(max.getX(), min.getY(), max.getZ()).toLocation(world)).setTo(new Vector(max.getX(), max.getY() + width, max.getZ()).toLocation(world)); + + lines.get(8).setFrom(new Vector(min.getX(), min.getY(), min.getZ()).toLocation(world)).setTo(new Vector(min.getX(), min.getY(), max.getZ() + width).toLocation(world)); + lines.get(9).setFrom(new Vector(max.getX(), min.getY(), min.getZ()).toLocation(world)).setTo(new Vector(max.getX(), min.getY(), max.getZ() + width).toLocation(world)); + lines.get(10).setFrom(new Vector(min.getX(), max.getY(), min.getZ()).toLocation(world)).setTo(new Vector(min.getX(), max.getY(), max.getZ() + width).toLocation(world)); + lines.get(11).setFrom(new Vector(max.getX(), max.getY(), min.getZ()).toLocation(world)).setTo(new Vector(max.getX(), max.getY(), max.getZ() + width).toLocation(world)); + } +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index d5ced5500..2d19e22cd 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -291,10 +291,8 @@ public class REntityServer implements Listener { } public void tick() { - for(HashSet entitiesInChunk : entities.values()) { - for(REntity entity : entitiesInChunk) { - entity.tick(); - } + for (REntity entity : entityMap.values()) { + entity.tick(); } } From 3e9ffa52c3fe145ab9cb913cad48b9c21a7d0e24 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 12 Jun 2025 19:19:38 +0200 Subject: [PATCH 046/153] Fix nit --- SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CLine.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CLine.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CLine.java index e145bb607..f3b02deb0 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CLine.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CLine.java @@ -41,6 +41,7 @@ public class CLine extends CEntity { private Location to; private float width = DEFAULT_WIDTH; private BlockData blockData = RBlockDisplay.DEFAULT_BLOCK; + private boolean hide = false; public CLine(REntityServer server) { super(server); @@ -78,8 +79,6 @@ public class CLine extends CEntity { return this; } - private boolean hide = false; - @Override public void hide(boolean hide) { if (hide == this.hide) return; From 37acbf00337f39af41a1354c39f513c0c339a6ce Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 12 Jun 2025 19:27:56 +0200 Subject: [PATCH 047/153] Add BlueInsetRegion management and implement TechareaCommand --- .../src/de/steamwar/sql/CheckedSchematic.java | 1 + .../src/de/steamwar/fightsystem/Config.java | 8 +++ .../de/steamwar/fightsystem/FightSystem.java | 2 + .../fightsystem/commands/TechareaCommand.java | 49 +++++++++++++++++++ .../de/steamwar/fightsystem/utils/Region.java | 9 ++++ 5 files changed, 69 insertions(+) create mode 100644 FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TechareaCommand.java diff --git a/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java b/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java index 59ed8d2f6..aa1e0986d 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java +++ b/CommonCore/SQL/src/de/steamwar/sql/CheckedSchematic.java @@ -28,6 +28,7 @@ import lombok.Getter; import java.sql.Timestamp; import java.util.List; +import java.util.concurrent.CompletableFuture; @AllArgsConstructor public class CheckedSchematic { diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index 7bac2bee5..11a2a07d1 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -59,6 +59,7 @@ public class Config { public static final Region RedExtendRegion; public static final Region ArenaRegion; public static final Region PlayerRegion; + public static final Region BlueInsetRegion; public static final Location TeamBlueSpawn; public static final Location TeamRedSpawn; @@ -193,6 +194,11 @@ public class Config { ReplaceWithBlockupdates = config.getBoolean("Schematic.ReplaceWithBlockupdates", false); UnlimitedPrepare = config.getBoolean("Schematic.UnlimitedPrepare", false); + int schemInsetX = config.getInt("Schematic.Inset.x", 0); + int schemInsetZ = config.getInt("Schematic.Inset.z", 0); + int schemInsetBottom = config.getInt("Schematic.Inset.bottom", 0); + int schemInsetTop = config.getInt("Schematic.Inset.top", 0); + GameName = config.getString("GameName", "WarGear"); TeamChatDetection = config.getString("TeamChatPrefix", "+"); @@ -318,6 +324,8 @@ public class Config { ArenaRegion = Region.withExtension(arenaMinX, blueCornerY, arenaMinZ, arenaMaxX - arenaMinX, schemsizeY, arenaMaxZ - arenaMinZ, 0, PreperationArea, 0); PlayerRegion = new Region(arenaMinX, underBorder, arenaMinZ, arenaMaxX, world.getMaxHeight(), arenaMaxZ); + BlueInsetRegion = new Region(BluePasteRegion.getMinX() + schemInsetX, BluePasteRegion.getMinY() + schemInsetBottom, BluePasteRegion.getMinZ() + schemInsetZ, BluePasteRegion.getMaxX() - schemInsetX, BluePasteRegion.getMaxY() - schemInsetTop, BluePasteRegion.getMaxZ() - schemInsetZ); + int eventKampfID = Integer.parseInt(System.getProperty("fightID", "0")); if(eventKampfID >= 1){ EventKampf = EventFight.get(eventKampfID); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index bff381708..ce47ee34f 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -177,6 +177,8 @@ public class FightSystem extends JavaPlugin { Fight.getRedTeam().setSchem(unpreparedSchematicNode); } } + + new TechareaCommand(); }else if(Config.mode == ArenaMode.PREPARE) { Fight.getUnrotated().setSchem(SchematicNode.getSchematicNode(Config.PrepareSchemID)); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TechareaCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TechareaCommand.java new file mode 100644 index 000000000..64eb11058 --- /dev/null +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TechareaCommand.java @@ -0,0 +1,49 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 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.fightsystem.commands; + +import de.steamwar.command.SWCommand; +import de.steamwar.entity.CWireframe; +import de.steamwar.entity.REntityServer; +import de.steamwar.fightsystem.Config; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +public class TechareaCommand extends SWCommand { + private final REntityServer server = new REntityServer(); + private final CWireframe wireframe = new CWireframe(server); + + public TechareaCommand() { + super("techarea"); + + wireframe.setPos1(Config.BlueInsetRegion.getMinLocation(Config.world)); + wireframe.setPos2(Config.BlueInsetRegion.getMaxLocation(Config.world)); + wireframe.setBlock(Material.RED_CONCRETE.createBlockData()); + } + + @Register + public void genericCommand(Player player) { + if (server.getPlayers().contains(player)) { + server.removePlayer(player); + } else { + server.addPlayer(player); + } + } +} diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java index 60d37be8d..2d8815133 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java @@ -23,6 +23,7 @@ import de.steamwar.techhider.ProtocolUtils; import lombok.AllArgsConstructor; import lombok.Getter; import org.bukkit.Location; +import org.bukkit.World; import org.bukkit.block.Block; import java.util.function.ObjIntConsumer; @@ -77,6 +78,14 @@ public class Region { return ProtocolUtils.posToChunk(maxZ); } + public Location getMinLocation(World world) { + return new Location(world, minX, minY, minZ); + } + + public Location getMaxLocation(World world) { + return new Location(world, maxX, maxY, maxZ); + } + public boolean chunkOutside(int cX, int cZ) { return getMinChunkX() > cX || cX > getMaxChunkX() || getMinChunkZ() > cZ || cZ > getMaxChunkZ(); From c9821053cee57bef3a30ac4459111ac8af460ec4 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 12 Jun 2025 19:45:45 +0200 Subject: [PATCH 048/153] Refactor TechareaCommand to support per-player REntityServer instances and add periodic tick updates --- .../fightsystem/commands/TechareaCommand.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TechareaCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TechareaCommand.java index 64eb11058..916bf8163 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TechareaCommand.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TechareaCommand.java @@ -23,27 +23,38 @@ import de.steamwar.command.SWCommand; import de.steamwar.entity.CWireframe; import de.steamwar.entity.REntityServer; import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + public class TechareaCommand extends SWCommand { - private final REntityServer server = new REntityServer(); - private final CWireframe wireframe = new CWireframe(server); + private final Map servers = new HashMap<>(); public TechareaCommand() { super("techarea"); - wireframe.setPos1(Config.BlueInsetRegion.getMinLocation(Config.world)); - wireframe.setPos2(Config.BlueInsetRegion.getMaxLocation(Config.world)); - wireframe.setBlock(Material.RED_CONCRETE.createBlockData()); + Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), () -> servers.forEach((uuid, rEntityServer) -> rEntityServer.tick()), 2, 2); } @Register public void genericCommand(Player player) { - if (server.getPlayers().contains(player)) { - server.removePlayer(player); + if (servers.containsKey(player.getUniqueId())) { + servers.get(player.getUniqueId()).close(); } else { + REntityServer server = new REntityServer(); + CWireframe wireframe = new CWireframe(server); + + wireframe.setPos1(Config.BlueInsetRegion.getMinLocation(Config.world)); + wireframe.setPos2(Config.BlueInsetRegion.getMaxLocation(Config.world)); + wireframe.setBlock(Material.RED_CONCRETE.createBlockData()); + server.addPlayer(player); + servers.put(player.getUniqueId(), server); } } } From 5201a3edc0f196247643fb611be54b4540e5df85 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 12 Jun 2025 19:53:22 +0200 Subject: [PATCH 049/153] Adjust TechareaCommand to refine wireframe bounds using offset subtraction --- .../src/de/steamwar/fightsystem/commands/TechareaCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TechareaCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TechareaCommand.java index 916bf8163..880e1843e 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TechareaCommand.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TechareaCommand.java @@ -50,7 +50,7 @@ public class TechareaCommand extends SWCommand { CWireframe wireframe = new CWireframe(server); wireframe.setPos1(Config.BlueInsetRegion.getMinLocation(Config.world)); - wireframe.setPos2(Config.BlueInsetRegion.getMaxLocation(Config.world)); + wireframe.setPos2(Config.BlueInsetRegion.getMaxLocation(Config.world).subtract(1, 1, 1)); wireframe.setBlock(Material.RED_CONCRETE.createBlockData()); server.addPlayer(player); From c3a4e7ed858081afd94902bfaf1b6ccde2c03fb2 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 12 Jun 2025 21:28:49 +0200 Subject: [PATCH 050/153] Improve network code --- .../src/de/steamwar/core/Promise.java | 47 ------------------- .../src/de/steamwar/entity/RPlayer.java | 20 ++++---- .../steamwar/network/CoreNetworkHandler.java | 7 ++- .../de/steamwar/network/NetworkSender.java | 15 ++---- .../network/handlers/PlayerSkinHandler.java | 28 +++++------ 5 files changed, 30 insertions(+), 87 deletions(-) delete mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/core/Promise.java diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Promise.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Promise.java deleted file mode 100644 index 393932f33..000000000 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Promise.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 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.core; - -import lombok.NoArgsConstructor; - -import java.util.concurrent.atomic.AtomicBoolean; - -@NoArgsConstructor -public class Promise { - - private AtomicBoolean hasValue = new AtomicBoolean(false); - private E value; - - public void setValue(E value) { - this.value = value; - hasValue.set(true); - } - - public E getValue() { - if (hasValue.get()) { - return value; - } - - while (hasValue.get()) { - Thread.yield(); - } - return value; - } -} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java index 5efdd3f9d..2575a7786 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java @@ -22,7 +22,10 @@ package de.steamwar.entity; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import de.steamwar.Reflection; -import de.steamwar.core.*; +import de.steamwar.core.BountifulWrapper; +import de.steamwar.core.Core; +import de.steamwar.core.FlatteningWrapper; +import de.steamwar.core.ProtocolWrapper; import de.steamwar.network.NetworkSender; import de.steamwar.network.packets.common.PlayerSkinRequestPacket; import lombok.Getter; @@ -72,22 +75,21 @@ public class RPlayer extends REntity { server.addEntity(this); } - public static final Map> SKIN_DATA_PROMISES = new LinkedHashMap>() { + public static final Map SKIN_DATA_PROMISES = new LinkedHashMap() { @Override - protected boolean removeEldestEntry(Map.Entry> eldest) { + protected boolean removeEldestEntry(Map.Entry eldest) { return size() > 100; } }; private GameProfile getGameProfile() { - Property property = SKIN_DATA_PROMISES.computeIfAbsent(uuid, __ -> { - Promise future = new Promise<>(); + Property skinData = SKIN_DATA_PROMISES.computeIfAbsent(uuid, __ -> { NetworkSender.sendOrQueue(new PlayerSkinRequestPacket(uuid)); - return future; - }).getValue(); - if (property != null) { + return new Property("textures", null, null); + }); + if (skinData.getValue() != null) { GameProfile gameProfile = new GameProfile(uuid, name); - gameProfile.getProperties().put("textures", property); + gameProfile.getProperties().put("textures", skinData); return gameProfile; } else { return new GameProfile(actualUUID, name); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/network/CoreNetworkHandler.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/network/CoreNetworkHandler.java index 407e9e414..50ee9fcb3 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/network/CoreNetworkHandler.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/network/CoreNetworkHandler.java @@ -21,7 +21,6 @@ package de.steamwar.network; import com.mojang.authlib.properties.Property; import de.steamwar.core.BountifulWrapper; -import de.steamwar.core.Promise; import de.steamwar.entity.RPlayer; import de.steamwar.network.handlers.InventoryHandler; import de.steamwar.network.packets.PacketHandler; @@ -75,8 +74,8 @@ public class CoreNetworkHandler extends PacketHandler { @Handler public void handlePlayerSkinResponse(PlayerSkinResponsePacket packet) { - Promise propertyPromise = RPlayer.SKIN_DATA_PROMISES.get(packet.getUuid()); - if (propertyPromise == null) return; - propertyPromise.setValue(new Property("textures", packet.getSkin(), packet.getSignature())); + Property property = RPlayer.SKIN_DATA_PROMISES.get(packet.getUuid()); + if (property == null) return; + RPlayer.SKIN_DATA_PROMISES.put(packet.getUuid(), new Property("textures", packet.getSkin(), packet.getSignature())); } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/network/NetworkSender.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/network/NetworkSender.java index 2dda8b929..8000ff23f 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/network/NetworkSender.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/network/NetworkSender.java @@ -27,15 +27,12 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerQuitEvent; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; public class NetworkSender implements Listener { - private static AtomicInteger numberOfPlayers = new AtomicInteger(0); private static List queued = new ArrayList<>(); static { @@ -47,21 +44,17 @@ public class NetworkSender implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { - numberOfPlayers.incrementAndGet(); - if (numberOfPlayers.get() > 1) return; + if (!Bukkit.getOnlinePlayers().isEmpty()) { + return; + } Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { queued.forEach(NetworkSender::send); queued.clear(); }, 1); } - @EventHandler - public void onPlayerQuit(PlayerQuitEvent event) { - numberOfPlayers.decrementAndGet(); - } - public static void sendOrQueue(NetworkPacket packet) { - if (numberOfPlayers.get() > 0) { + if (!Bukkit.getOnlinePlayers().isEmpty()) { send(packet); } else { queued.add(packet); diff --git a/VelocityCore/src/de/steamwar/velocitycore/network/handlers/PlayerSkinHandler.java b/VelocityCore/src/de/steamwar/velocitycore/network/handlers/PlayerSkinHandler.java index 0baf15ba3..0515212e2 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/network/handlers/PlayerSkinHandler.java +++ b/VelocityCore/src/de/steamwar/velocitycore/network/handlers/PlayerSkinHandler.java @@ -30,10 +30,11 @@ import com.velocitypowered.api.util.GameProfile; import de.steamwar.network.packets.PacketHandler; import de.steamwar.network.packets.common.PlayerSkinRequestPacket; import de.steamwar.network.packets.common.PlayerSkinResponsePacket; -import de.steamwar.persistent.Storage; import de.steamwar.velocitycore.VelocityCore; import de.steamwar.velocitycore.network.NetworkSender; import de.steamwar.velocitycore.network.ServerMetaInfo; +import lombok.AllArgsConstructor; +import lombok.Data; import lombok.SneakyThrows; import java.io.BufferedReader; @@ -55,15 +56,9 @@ public class PlayerSkinHandler extends PacketHandler { VelocityCore.getProxy().getEventManager().register(VelocityCore.get(), this); } - private Map skins = new LinkedHashMap<>() { + private Map skins = new LinkedHashMap<>() { @Override - protected boolean removeEldestEntry(Map.Entry eldest) { - return size() > maxCacheSize; - } - }; - private Map signatures = new LinkedHashMap<>() { - @Override - protected boolean removeEldestEntry(Map.Entry eldest) { + protected boolean removeEldestEntry(Map.Entry eldest) { return size() > maxCacheSize; } }; @@ -71,8 +66,9 @@ public class PlayerSkinHandler extends PacketHandler { @Handler @SneakyThrows public void handle(PlayerSkinRequestPacket packet) { - if (skins.containsKey(packet.getUuid()) && signatures.containsKey(packet.getUuid())) { - NetworkSender.send(((ServerMetaInfo) packet.getMetaInfos()).sender().getServer(), new PlayerSkinResponsePacket(packet.getUuid(), skins.get(packet.getUuid()), signatures.get(packet.getUuid()))); + if (skins.containsKey(packet.getUuid())) { + SkinData skinData = skins.get(packet.getUuid()); + NetworkSender.send(((ServerMetaInfo) packet.getMetaInfos()).sender().getServer(), new PlayerSkinResponsePacket(packet.getUuid(), skinData.skin, skinData.signature)); return; } @@ -98,8 +94,7 @@ public class PlayerSkinHandler extends PacketHandler { if (prop.get("name").getAsString().equals("textures")) { String skin = prop.get("value").getAsString(); String signature = prop.get("signature").getAsString(); - skins.put(packet.getUuid(), skin); - signatures.put(packet.getUuid(), signature); + skins.put(packet.getUuid(), new SkinData(skin, signature)); NetworkSender.send(((ServerMetaInfo) packet.getMetaInfos()).sender().getServer(), new PlayerSkinResponsePacket(packet.getUuid(), skin, signature)); return; } @@ -112,14 +107,15 @@ public class PlayerSkinHandler extends PacketHandler { GameProfile gameProfile = player.getGameProfile(); GameProfile.Property property = gameProfile.getProperties().stream().filter(p -> p.getName().equals("textures")).findFirst().orElse(null); if (property == null) return; - skins.put(player.getUniqueId(), property.getValue()); - signatures.put(player.getUniqueId(), property.getSignature()); + skins.put(player.getUniqueId(), new SkinData(property.getValue(), property.getSignature())); Set uuidSet = skins.keySet(); VelocityCore.getProxy().getAllServers().forEach(server -> { for (UUID uuid : uuidSet) { - NetworkSender.send(server, new PlayerSkinResponsePacket(uuid, skins.get(uuid), signatures.get(uuid))); + NetworkSender.send(server, new PlayerSkinResponsePacket(uuid, property.getValue(), property.getSignature())); } }); } + + public record SkinData(String skin, String signature) {} } From 4eb40581f26199943169365cab9e5a6008f0c1c4 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 12 Jun 2025 22:07:24 +0200 Subject: [PATCH 051/153] Hotfix TexturePackSystem --- .../listeners/TexturePackSystem.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/TexturePackSystem.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/TexturePackSystem.java index cebe9d6d2..8d07e0c73 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/TexturePackSystem.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/TexturePackSystem.java @@ -42,16 +42,17 @@ public class TexturePackSystem extends BasicListener { public TexturePackSystem() { // https://minecraft.wiki/w/Pack_format#List_of_resource_pack_formats // https://minecraft.wiki/w/Minecraft_Wiki:Projects/wiki.vg_merge/Protocol_version_numbers - protocolVersionToPackVersion.put(759, 10); // 1.19 - 1.19.3 - protocolVersionToPackVersion.put(762, 12); // 1.19.4 - protocolVersionToPackVersion.put(763, 15); // 1.20 - 1.20.1 - protocolVersionToPackVersion.put(764, 18); // 1.20.2 - protocolVersionToPackVersion.put(765, 26); // 1.20.3 - 1.20.4 - protocolVersionToPackVersion.put(766, 41); // 1.20.5 - 1.20.6 - protocolVersionToPackVersion.put(767, 48); // 1.21 - 1.21.1 - protocolVersionToPackVersion.put(768, 57); // 1.21.2 - 1.21.3 - protocolVersionToPackVersion.put(769, 61); // 1.21.4 - protocolVersionToPackVersion.put(770, 71); // 1.21.5 + protocolVersionToPackVersion.put(759, 9); + protocolVersionToPackVersion.put(761, 12); + protocolVersionToPackVersion.put(762, 13); + protocolVersionToPackVersion.put(763, 15); + protocolVersionToPackVersion.put(764, 18); + protocolVersionToPackVersion.put(765, 22); + protocolVersionToPackVersion.put(766, 32); + protocolVersionToPackVersion.put(767, 34); + protocolVersionToPackVersion.put(768, 42); + protocolVersionToPackVersion.put(769, 46); + protocolVersionToPackVersion.put(770, 55); } @Subscribe From 9abbcc908d24ccadc5749253d60ccca486b3c8b7 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 14 Jun 2025 21:56:02 +0200 Subject: [PATCH 052/153] Remove unused fillRegion method from WorldEdit wrapper and related code --- .../fightsystem/utils/WorldeditWrapper14.java | 15 --------------- .../fightsystem/utils/WorldeditWrapper8.java | 12 ------------ .../steamwar/fightsystem/commands/WGCommand.java | 2 ++ .../fightsystem/fight/FightSchematic.java | 4 ---- .../fightsystem/utils/WorldeditWrapper.java | 3 --- 5 files changed, 2 insertions(+), 34 deletions(-) diff --git a/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java b/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java index e26c8525e..9a0ae4b52 100644 --- a/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java +++ b/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java @@ -21,11 +21,9 @@ package de.steamwar.fightsystem.utils; import com.sk89q.jnbt.NBTInputStream; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldedit.bukkit.BukkitBlockRegistry; import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; @@ -41,7 +39,6 @@ import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; @@ -50,7 +47,6 @@ import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; import org.bukkit.DyeColor; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.util.Vector; import java.io.ByteArrayOutputStream; @@ -151,15 +147,4 @@ public class WorldeditWrapper14 implements WorldeditWrapper { new SchematicData(schem).saveFromBytes(outputStream.toByteArray(), NodeData.SchematicFormat.SPONGE_V2); } - - @Override - public void fillRegion(org.bukkit.World world, Region region, Material material) { - EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(world), -1); - try { - e.setBlocks(new CuboidRegion(new BukkitWorld(world), BlockVector3.at(region.getMinX(), region.getMinY(), region.getMinZ()), BlockVector3.at(region.getMaxX(), region.getMaxY(), region.getMaxZ())), BlockTypes.get(material.name()).getDefaultState().toBaseBlock()); - } catch (MaxChangedBlocksException ex) { - throw new RuntimeException(ex); - } - e.flushSession(); - } } diff --git a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java index 58d51350a..d0479e46e 100644 --- a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java +++ b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java @@ -22,7 +22,6 @@ package de.steamwar.fightsystem.utils; import com.sk89q.jnbt.NBTInputStream; import com.sk89q.worldedit.*; import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.blocks.BlockType; import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; @@ -143,15 +142,4 @@ public class WorldeditWrapper8 implements WorldeditWrapper { new SchematicData(schem).saveFromBytes(outputStream.toByteArray(), NodeData.SchematicFormat.MCEDIT); } - - @Override - public void fillRegion(org.bukkit.World world, Region region, Material material) { - EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(world), -1); - try { - e.setBlocks(new CuboidRegion(new BukkitWorld(world), BlockVector.toBlockPoint(region.getMinX(), region.getMinY(), region.getMinZ()), BlockVector.toBlockPoint(region.getMaxX(), region.getMaxY(), region.getMaxZ())), new BaseBlock(BlockType.lookup(material.name()).getID())); - } catch (MaxChangedBlocksException ex) { - throw new RuntimeException(ex); - } - e.flushQueue(); - } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/WGCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/WGCommand.java index edb891fc9..c1157018e 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/WGCommand.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/WGCommand.java @@ -21,6 +21,7 @@ package de.steamwar.fightsystem.commands; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightWorld; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentCommand; import org.bukkit.command.Command; @@ -39,6 +40,7 @@ public class WGCommand implements CommandExecutor { if(!(sender instanceof Player)) { return false; } + FightWorld.resetWorld(); Fight.getBlueTeam().pasteSchem(); return false; } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index 2c8fc7161..d566c0224 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -141,10 +141,6 @@ public class FightSchematic extends StateDependent { team.teleportToSpawn(); - if(Config.mode == ArenaMode.CHECK) { - WorldeditWrapper.impl.fillRegion(Config.world, region, Material.AIR); - } - Vector dims = WorldeditWrapper.impl.getDimensions(clipboard); WorldeditWrapper.impl.pasteClipboard( clipboard, diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java index f486c4d64..83c688039 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java @@ -27,8 +27,6 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.sql.SchematicNode; import org.bukkit.DyeColor; import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; import org.bukkit.util.Vector; import java.io.IOException; @@ -42,5 +40,4 @@ public interface WorldeditWrapper { Vector getDimensions(Clipboard clipboard); Clipboard loadChar(String charName) throws IOException; void saveSchem(SchematicNode schem, Region region, int minY) throws WorldEditException; - void fillRegion(World world, Region region, Material material); } From fcebb4ffd3f72fa0a4a27e95f7f3d9658044be81 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 14 Jun 2025 22:01:29 +0200 Subject: [PATCH 053/153] Add red team schematic paste in WGCommand --- .../src/de/steamwar/fightsystem/commands/WGCommand.java | 1 + 1 file changed, 1 insertion(+) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/WGCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/WGCommand.java index c1157018e..1ffe7dce5 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/WGCommand.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/WGCommand.java @@ -42,6 +42,7 @@ public class WGCommand implements CommandExecutor { } FightWorld.resetWorld(); Fight.getBlueTeam().pasteSchem(); + Fight.getRedTeam().pasteSchem(); return false; } } From 75c4966e37cbb2536c82de7f305435d23f1b1fa7 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 26 Jun 2025 13:52:01 +0200 Subject: [PATCH 054/153] Fix SimulatorTNTGui for 1.19 --- .../simulator/gui/SimulatorTNTGui.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java index 75c2c8761..471270c9b 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java @@ -29,6 +29,7 @@ import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorScrollGui; import de.steamwar.bausystem.region.Region; +import de.steamwar.core.Core; import de.steamwar.data.CMDs; import de.steamwar.inventory.SWItem; import org.bukkit.Material; @@ -101,14 +102,16 @@ public class SimulatorTNTGui extends SimulatorScrollGui { tnt.setDisabled(!tnt.isDisabled()); SimulatorWatcher.update(simulator); }).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED)); - inventory.setItem(49, new SWItem(Material.CALIBRATED_SCULK_SENSOR, "§eCreate Stab", click -> { - new SimulatorAnvilGui<>(player, "Depth Limit", "", Integer::parseInt, depthLimit -> { - if (depthLimit <= 0) return false; - simulator.setStabGenerator(new SimulatorStabGenerator(Region.getRegion(player.getLocation()), simulator, tnt, depthLimit)); - SimulatorWatcher.update(simulator); - return true; - }, null).open(); - }).setCustomModelData(CMDs.Simulator.CREATE_STAB)); + if (Core.getVersion() > 19) { + inventory.setItem(49, new SWItem(Material.CALIBRATED_SCULK_SENSOR, "§eCreate Stab", click -> { + new SimulatorAnvilGui<>(player, "Depth Limit", "", Integer::parseInt, depthLimit -> { + if (depthLimit <= 0) return false; + simulator.setStabGenerator(new SimulatorStabGenerator(Region.getRegion(player.getLocation()), simulator, tnt, depthLimit)); + SimulatorWatcher.update(simulator); + return true; + }, null).open(); + }).setCustomModelData(CMDs.Simulator.CREATE_STAB)); + } inventory.setItem(50, new SWItem(Material.CHEST, parent.getElements().size() == 1 ? "§eMake Group" : "§eAdd another TNT to Group", clickType -> { TNTElement tntElement = new TNTElement(tnt.getPosition().clone()); tntElement.add(new TNTPhase()); From 77cf1018897efbd127c5dfa2a105f3756ec7accb Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 26 Jun 2025 14:49:48 +0200 Subject: [PATCH 055/153] Add BauLockState.SUPERVISOR --- VelocityCore/src/de/steamwar/velocitycore/util/BauLock.java | 5 +++++ .../src/de/steamwar/velocitycore/util/BauLockState.java | 1 + 2 files changed, 6 insertions(+) diff --git a/VelocityCore/src/de/steamwar/velocitycore/util/BauLock.java b/VelocityCore/src/de/steamwar/velocitycore/util/BauLock.java index 03bc43151..7f95599b3 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/util/BauLock.java +++ b/VelocityCore/src/de/steamwar/velocitycore/util/BauLock.java @@ -20,6 +20,7 @@ package de.steamwar.velocitycore.util; import de.steamwar.messages.Chatter; +import de.steamwar.sql.BauweltMember; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserConfig; import de.steamwar.sql.UserPerm; @@ -44,6 +45,10 @@ public class BauLock { case NOBODY: locked = true; break; + case SUPERVISOR: + BauweltMember member = BauweltMember.getBauMember(owner.getId(), target.getId()); + locked = !member.isSupervisor(); + break; case SERVERTEAM: locked = !target.hasPerm(UserPerm.TEAM); break; diff --git a/VelocityCore/src/de/steamwar/velocitycore/util/BauLockState.java b/VelocityCore/src/de/steamwar/velocitycore/util/BauLockState.java index 8fe89bf93..c6b8af4ff 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/util/BauLockState.java +++ b/VelocityCore/src/de/steamwar/velocitycore/util/BauLockState.java @@ -22,6 +22,7 @@ package de.steamwar.velocitycore.util; public enum BauLockState { NOBODY, // Locks the build server for all users + SUPERVISOR, // Locks the build server for supervisors SERVERTEAM, // opens the build server only for every added user which is a server team member TEAM_AND_SERVERTEAM, //opens the build server only for every added user which is in the same team as the buildOwner and every server team member TEAM, //opens the build server only for every added user which is in the same team as the buildOwner From 187087f56ba627a21318d4de369dc347376c2dea Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 26 Jun 2025 20:20:55 +0200 Subject: [PATCH 056/153] Fix LaufbauSettings --- BauSystem/BauSystem_Main/src/BauSystem.properties | 2 +- BauSystem/BauSystem_Main/src/BauSystem_de.properties | 2 +- .../bausystem/features/slaves/laufbau/LaufbauSettings.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/BauSystem.properties b/BauSystem/BauSystem_Main/src/BauSystem.properties index 90f1d4cf6..1794779af 100644 --- a/BauSystem/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem/BauSystem_Main/src/BauSystem.properties @@ -846,7 +846,7 @@ LAUFBAU_SETTINGS_INACTIVE=§cInactive LAUFBAU_SETTINGS_MIXED=§e{0}§8/§e{1} §aActive LAUFBAU_SETTINGS_GUI_BACK=§eBack LAUFBAU_SETTINGS_TOGGLE=§eClick §8-§7 Toggle -LAUFBAU_SETTINGS_ADVANCED=§eMiddle-Click §8-§7 Advanced settings +LAUFBAU_SETTINGS_ADVANCED=§eLeft-Click §8-§7 Advanced settings LAUFBAU_BLOCK_COBWEB=§eCobweb LAUFBAU_BLOCK_GRASS_PATH=§eGrass Path LAUFBAU_BLOCK_SOUL_SAND=§eSoul Sand diff --git a/BauSystem/BauSystem_Main/src/BauSystem_de.properties b/BauSystem/BauSystem_Main/src/BauSystem_de.properties index fca76eb9c..a8f67bcb6 100644 --- a/BauSystem/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem/BauSystem_Main/src/BauSystem_de.properties @@ -792,7 +792,7 @@ LAUFBAU_SETTINGS_INACTIVE=§cInaktiv LAUFBAU_SETTINGS_MIXED=§e{0}§8/§e{1} §aAktiv LAUFBAU_SETTINGS_GUI_BACK=§eBack LAUFBAU_SETTINGS_TOGGLE=§eClick §8-§7 Toggle -LAUFBAU_SETTINGS_ADVANCED=§eMiddle-Click §8-§7 Erweiterte Einstellung +LAUFBAU_SETTINGS_ADVANCED=§eLinks-Click §8-§7 Erweiterte Einstellung LAUFBAU_BLOCK_COBWEB=§eCobweb LAUFBAU_BLOCK_GRASS_PATH=§eGrass Path LAUFBAU_BLOCK_SOUL_SAND=§eSoul Sand diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauSettings.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauSettings.java index 51c482abe..17de9c68e 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauSettings.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauSettings.java @@ -60,7 +60,7 @@ public class LaufbauSettings { open(); return; } - if (clickType.isCreativeAction()) { + if (clickType.isLeftClick()) { open(entry.getKey()); return; } From 1c8d6580d59bbc76c52150081294f23fc8a1c265 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 26 Jun 2025 21:01:29 +0200 Subject: [PATCH 057/153] Fix Scoreboard --- BauSystem/BauSystem_Main/src/BauSystem.properties | 1 + .../bausystem/features/world/BauLockStateScoreboard.java | 1 + 2 files changed, 2 insertions(+) diff --git a/BauSystem/BauSystem_Main/src/BauSystem.properties b/BauSystem/BauSystem_Main/src/BauSystem.properties index 90f1d4cf6..5a4a2da26 100644 --- a/BauSystem/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem/BauSystem_Main/src/BauSystem.properties @@ -38,6 +38,7 @@ SCOREBOARD_TRACE_TICKS=Ticks SCOREBOARD_TECHHIDER=TechHider§8: §aOn SCOREBOARD_XRAY=XRay§8: §aOn SCOREBOARD_LOCK_TEAM=Bau Lock§8: §eTeam +SCOREBOARD_LOCK_SUPERVISOR=Bau Lock§8: §eSupervisor SCOREBOARD_LOCK_TEAM_AND_SERVERTEAM=Bau Lock§8: §e(Server) Team SCOREBOARD_LOCK_SERVERTEAM=Bau Lock§8: §eServer Team SCOREBOARD_LOCK_NOBODY=Bau Lock§8: §cNobody diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauLockStateScoreboard.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauLockStateScoreboard.java index ab3630d44..3e1593110 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauLockStateScoreboard.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauLockStateScoreboard.java @@ -59,6 +59,7 @@ public class BauLockStateScoreboard implements ScoreboardElement { public enum BauLockState { NOBODY, + SUPERVISOR, SERVERTEAM, TEAM_AND_SERVERTEAM, TEAM, From dccb435bce5ba78fa20a58e096408c9452c706fb Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 30 Mar 2025 17:39:47 +0200 Subject: [PATCH 058/153] Update WorldEdit CUI to RBlockDisplay --- SpigotCore/SpigotCore_20/build.gradle.kts | 1 + .../de/steamwar/core/WorldEditRenderer20.java | 217 ++++++++++++++++++ .../core/renderers/CuboidRegionRenderer.java | 159 +++++++++++++ .../core/renderers/RegionRenderer.java | 47 ++++ .../de/steamwar/core/WorldEditRenderer8.java | 23 ++ SpigotCore/SpigotCore_9/build.gradle.kts | 1 + .../de/steamwar/core/WorldEditRenderer9.java | 125 ++++++++++ .../src/de/steamwar/core/Core.java | 4 +- .../de/steamwar/core/WorldEditRenderer.java | 129 ++--------- 9 files changed, 590 insertions(+), 116 deletions(-) create mode 100644 SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRenderer20.java create mode 100644 SpigotCore/SpigotCore_20/src/de/steamwar/core/renderers/CuboidRegionRenderer.java create mode 100644 SpigotCore/SpigotCore_20/src/de/steamwar/core/renderers/RegionRenderer.java create mode 100644 SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditRenderer8.java create mode 100644 SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRenderer9.java diff --git a/SpigotCore/SpigotCore_20/build.gradle.kts b/SpigotCore/SpigotCore_20/build.gradle.kts index 3e894ccc5..258086310 100644 --- a/SpigotCore/SpigotCore_20/build.gradle.kts +++ b/SpigotCore/SpigotCore_20/build.gradle.kts @@ -26,5 +26,6 @@ dependencies { compileOnly(libs.spigotapi) + compileOnly(libs.worldedit15) compileOnly(libs.nms20) } diff --git a/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRenderer20.java b/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRenderer20.java new file mode 100644 index 000000000..d84f4abb5 --- /dev/null +++ b/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRenderer20.java @@ -0,0 +1,217 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.core; + +import com.sk89q.worldedit.EmptyClipboardException; +import com.sk89q.worldedit.IncompleteRegionException; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.regions.RegionSelector; +import com.sk89q.worldedit.world.World; +import de.steamwar.core.renderers.CuboidRegionRenderer; +import de.steamwar.core.renderers.RegionRenderer; +import de.steamwar.entity.REntityServer; +import org.bukkit.Bukkit; +import org.bukkit.Material; +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.BlockBreakEvent; +import org.bukkit.event.player.*; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Supplier; + +public class WorldEditRenderer20 implements WorldEditRenderer, Listener { + + private static final Map servers = new HashMap<>(); + private static final Map clipboards = new HashMap<>(); + private static final Map regionSelections = new HashMap<>(); + + private static final Material WAND = FlatteningWrapper.impl.getMaterial("WOOD_AXE"); + + private final WorldEditPlugin we; + + private static final Map, Supplier>> rendererMap = new HashMap<>(); + + static { + rendererMap.put(CuboidRegion.class, CuboidRegionRenderer::new); + } + + public WorldEditRenderer20() { + we = WorldEditWrapper.getWorldEditPlugin(); + Bukkit.getPluginManager().registerEvents(this, Core.getInstance()); + Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> { + for (Player player : Bukkit.getOnlinePlayers()) { + render(player); + } + }, 10, 10); + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onPlayerJoin(PlayerJoinEvent event) { + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { + render(event.getPlayer()); + }, 0); + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) { + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { + render(event.getPlayer()); + }, 0); + } + + @EventHandler + public void onPlayerDropItem(PlayerDropItemEvent event) { + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { + render(event.getPlayer()); + }, 0); + } + + @EventHandler + public void onPlayerItemHeld(PlayerItemHeldEvent event) { + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { + render(event.getPlayer()); + }, 0); + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onBlockBreak(BlockBreakEvent event) { + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { + render(event.getPlayer()); + }, 0); + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onPlayerInteract(PlayerInteractEvent event) { + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { + render(event.getPlayer()); + }, 0); + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onPlayerMove(PlayerMoveEvent event) { + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { + render(event.getPlayer(), true, false); + }, 0); + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onPlayerQuit(PlayerQuitEvent event) { + REntityServer server = servers.remove(event.getPlayer()); + clipboards.remove(event.getPlayer()); + regionSelections.remove(event.getPlayer()); + if (server == null) return; + server.close(); + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { + String command = event.getMessage().split(" ")[0]; + command = command.replaceFirst("/", ""); + command = command.toLowerCase(); + if (WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().getCommandManager().containsCommand(command)) { + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { + render(event.getPlayer()); + }, 10); + } + } + + private void render(Player player) { + render(player, true, true); + } + + private void render(Player player, boolean renderClipboard, boolean renderRegionSelection) { + if (player.getInventory().getItemInMainHand().getType() != WAND) { + REntityServer entityServer = servers.remove(player); + clipboards.remove(player); + regionSelections.remove(player); + if (entityServer != null) entityServer.close(); + return; + } + + REntityServer server = servers.computeIfAbsent(player, __ -> { + REntityServer _server = new REntityServer(); + _server.addPlayer(player); + return _server; + }); + + LocalSession session = we.getSession(player); + if (renderClipboard) { + renderClipboard(server, session, player); + } + if (renderRegionSelection) { + renderSelection(server, session, player); + } + } + + @SuppressWarnings("unchecked") + private void renderClipboard(REntityServer server, LocalSession session, Player player) { + try { + Region region = session.getClipboard().getClipboard().getRegion(); + clipboards.compute(player, (__, regionRenderer) -> { + if (regionRenderer != null && !regionRenderer.canDisplay(region)) { + regionRenderer.clear(); + regionRenderer = null; + } + if (regionRenderer == null) { + return rendererMap.getOrDefault(region.getClass(), RegionRenderer.NOOPImpl::new).get(); + } else { + return regionRenderer; + } + }).update(server, region, session.getClipboard(), Material.LIME_CONCRETE.createBlockData()); + } catch (EmptyClipboardException e) { + RegionRenderer regionRenderer = clipboards.remove(player); + if (regionRenderer != null) regionRenderer.clear(); + } + } + + @SuppressWarnings("unchecked") + private void renderSelection(REntityServer server, LocalSession session, Player player) { + World world = session.getSelectionWorld(); + if (world == null) { + return; + } + RegionSelector regionSelector = session.getRegionSelector(world); + try { + Region region = regionSelector.getRegion(); + regionSelections.compute(player, (__, regionRenderer) -> { + if (regionRenderer != null && !regionRenderer.canDisplay(region)) { + regionRenderer.clear(); + regionRenderer = null; + } + if (regionRenderer == null) { + return rendererMap.getOrDefault(region.getClass(), RegionRenderer.NOOPImpl::new).get(); + } else { + return regionRenderer; + } + }).update(server, region, null, Material.PURPLE_CONCRETE.createBlockData()); + } catch (IncompleteRegionException e) { + RegionRenderer regionRenderer = regionSelections.remove(player); + if (regionRenderer != null) regionRenderer.clear(); + } + } +} diff --git a/SpigotCore/SpigotCore_20/src/de/steamwar/core/renderers/CuboidRegionRenderer.java b/SpigotCore/SpigotCore_20/src/de/steamwar/core/renderers/CuboidRegionRenderer.java new file mode 100644 index 000000000..70391d3db --- /dev/null +++ b/SpigotCore/SpigotCore_20/src/de/steamwar/core/renderers/CuboidRegionRenderer.java @@ -0,0 +1,159 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.core.renderers; + +import com.sk89q.worldedit.math.transform.Transform; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.session.ClipboardHolder; +import de.steamwar.core.WorldEditWrapper; +import de.steamwar.entity.RBlockDisplay; +import de.steamwar.entity.REntityServer; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.data.BlockData; +import org.bukkit.entity.Display; +import org.bukkit.entity.Player; +import org.bukkit.util.Transformation; +import org.bukkit.util.Vector; +import org.joml.Quaternionf; +import org.joml.Vector3f; + +public class CuboidRegionRenderer implements RegionRenderer { + + private static final World WORLD = Bukkit.getWorlds().get(0); + private static final float offset = 1 / 1024f; + private static final float width = 1 / 16f; + + private Vector lastA = null; + private Vector lastB = null; + + private RBlockDisplay bd01; + private RBlockDisplay bd02; + private RBlockDisplay bd03; + private RBlockDisplay bd04; + private RBlockDisplay bd05; + private RBlockDisplay bd06; + private RBlockDisplay bd07; + private RBlockDisplay bd08; + private RBlockDisplay bd09; + private RBlockDisplay bd10; + private RBlockDisplay bd11; + private RBlockDisplay bd12; + + @Override + public boolean canDisplay(Region region) { + return region instanceof CuboidRegion; + } + + public void update(REntityServer server, CuboidRegion region, ClipboardHolder holder, BlockData block) { + Vector a; + Vector b; + if (holder != null) { + Player player = server.getPlayers().stream().findFirst().orElse(null); + if (player == null) return; + Vector pos = player.getLocation().toVector(); + Transform transform = holder.getTransform(); + a = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMinimum(region).subtract(WorldEditWrapper.impl.getOrigin(holder.getClipboard())), transform).add(pos); + b = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMaximum(region).subtract(WorldEditWrapper.impl.getOrigin(holder.getClipboard())), transform).add(pos); + } else { + a = WorldEditWrapper.impl.getMinimum(region); + b = WorldEditWrapper.impl.getMaximum(region); + } + + if (a.equals(lastA) && b.equals(lastB)) { + return; + } + + drawCuboid(server, toBlockVector(a), toBlockVector(b), block); + } + + @Override + public void clear() { + if (bd01 != null) bd01.die(); + if (bd02 != null) bd02.die(); + if (bd03 != null) bd03.die(); + if (bd04 != null) bd04.die(); + if (bd05 != null) bd05.die(); + if (bd06 != null) bd06.die(); + if (bd07 != null) bd07.die(); + if (bd08 != null) bd08.die(); + if (bd09 != null) bd09.die(); + if (bd10 != null) bd10.die(); + if (bd11 != null) bd11.die(); + if (bd12 != null) bd12.die(); + } + + private void drawCuboid(REntityServer server, Vector min, Vector max, BlockData block) { + max.add(new Vector(1 - width, 1 - width, 1 - width)); + + bd01 = drawLine(bd01, server, new Vector(min.getX() - offset, min.getY(), min.getZ()), new Vector(max.getX() + width, min.getY(), min.getZ()), block); + bd02 = drawLine(bd02, server, new Vector(min.getX() - offset, max.getY(), min.getZ()), new Vector(max.getX() + width, max.getY(), min.getZ()), block); + bd03 = drawLine(bd03, server, new Vector(min.getX() - offset, min.getY(), max.getZ()), new Vector(max.getX() + width, min.getY(), max.getZ()), block); + bd04 = drawLine(bd04, server, new Vector(min.getX() - offset, max.getY(), max.getZ()), new Vector(max.getX() + width, max.getY(), max.getZ()), block); + + bd05 = drawLine(bd05, server, new Vector(min.getX(), min.getY() - offset, min.getZ()), new Vector(min.getX(), max.getY() + width, min.getZ()), block); + bd06 = drawLine(bd06, server, new Vector(max.getX(), min.getY() - offset, min.getZ()), new Vector(max.getX(), max.getY() + width, min.getZ()), block); + bd07 = drawLine(bd07, server, new Vector(min.getX(), min.getY() - offset, max.getZ()), new Vector(min.getX(), max.getY() + width, max.getZ()), block); + bd08 = drawLine(bd08, server, new Vector(max.getX(), min.getY() - offset, max.getZ()), new Vector(max.getX(), max.getY() + width, max.getZ()), block); + + bd09 = drawLine(bd09, server, new Vector(min.getX(), min.getY(), min.getZ() - offset), new Vector(min.getX(), min.getY(), max.getZ() + width), block); + bd10 = drawLine(bd10, server, new Vector(max.getX(), min.getY(), min.getZ() - offset), new Vector(max.getX(), min.getY(), max.getZ() + width), block); + bd11 = drawLine(bd11, server, new Vector(min.getX(), max.getY(), min.getZ() - offset), new Vector(min.getX(), max.getY(), max.getZ() + width), block); + bd12 = drawLine(bd12, server, new Vector(max.getX(), max.getY(), min.getZ() - offset), new Vector(max.getX(), max.getY(), max.getZ() + width), block); + } + + private RBlockDisplay drawLine(RBlockDisplay display, REntityServer server, Vector from, Vector to, BlockData block) { + Location spawnLocation = from.clone().add(to).divide(new Vector(2, 2, 2)).toLocation(WORLD); + if (display == null) { + display = new RBlockDisplay(server, spawnLocation); + } + + Vector vector = to.clone().subtract(from); + if (vector.getX() == 0) { + vector.setX(vector.getX() + width + offset * 2); + } + if (vector.getY() == 0) { + vector.setY(vector.getY() + width + offset * 2); + } + if (vector.getZ() == 0) { + vector.setZ(vector.getZ() + width + offset * 2); + } + + Vector transformVec = from.subtract(spawnLocation.toVector()); + transformVec.subtract(new Vector(offset, offset, offset)); + + display.setTransform(new Transformation(toVec3f(transformVec), new Quaternionf(0, 0, 0, 1), toVec3f(vector), new Quaternionf(0, 0, 0, 1))); + display.setBrightness(new Display.Brightness(15, 15)); + display.setBlock(block); + display.move(spawnLocation); + + return display; + } + + private Vector toBlockVector(Vector vector) { + return new Vector(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); + } + + private Vector3f toVec3f(Vector vector) { + return new Vector3f((float) vector.getX(), (float) vector.getY(), (float) vector.getZ()); + } +} diff --git a/SpigotCore/SpigotCore_20/src/de/steamwar/core/renderers/RegionRenderer.java b/SpigotCore/SpigotCore_20/src/de/steamwar/core/renderers/RegionRenderer.java new file mode 100644 index 000000000..53121deb2 --- /dev/null +++ b/SpigotCore/SpigotCore_20/src/de/steamwar/core/renderers/RegionRenderer.java @@ -0,0 +1,47 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.core.renderers; + +import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.session.ClipboardHolder; +import de.steamwar.entity.REntityServer; +import org.bukkit.block.data.BlockData; + +public interface RegionRenderer { + + boolean canDisplay(Region region); + void update(REntityServer server, R region, ClipboardHolder holder, BlockData block); + void clear(); + + final class NOOPImpl implements RegionRenderer { + @Override + public boolean canDisplay(Region region) { + return false; + } + + @Override + public void update(REntityServer server, Region region, ClipboardHolder holder, BlockData block) { + } + + @Override + public void clear() { + } + } +} diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditRenderer8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditRenderer8.java new file mode 100644 index 000000000..df3a66335 --- /dev/null +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditRenderer8.java @@ -0,0 +1,23 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.core; + +public class WorldEditRenderer8 implements WorldEditRenderer { +} diff --git a/SpigotCore/SpigotCore_9/build.gradle.kts b/SpigotCore/SpigotCore_9/build.gradle.kts index a888faf14..c149a3fd3 100644 --- a/SpigotCore/SpigotCore_9/build.gradle.kts +++ b/SpigotCore/SpigotCore_9/build.gradle.kts @@ -26,4 +26,5 @@ dependencies { compileOnly(project(":SpigotCore:SpigotCore_8", "default")) compileOnly(libs.nms9) + compileOnly(libs.worldedit12) } diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRenderer9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRenderer9.java new file mode 100644 index 000000000..971a759c7 --- /dev/null +++ b/SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRenderer9.java @@ -0,0 +1,125 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.core; + +import com.sk89q.worldedit.EmptyClipboardException; +import com.sk89q.worldedit.IncompleteRegionException; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.math.transform.Transform; +import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.regions.RegionSelector; +import com.sk89q.worldedit.world.World; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +public class WorldEditRenderer9 implements WorldEditRenderer { + + private static final int VIEW_DISTANCE = 64; + private static final int SQ_VIEW_DISTANCE = VIEW_DISTANCE * VIEW_DISTANCE; + + private static final double STEP_SIZE = 0.5; + + private static final Vector ONES = new Vector(1, 1, 1); + + private static final Material WAND = FlatteningWrapper.impl.getMaterial("WOOD_AXE"); + + private final WorldEditPlugin we; + + public WorldEditRenderer9() { + we = WorldEditWrapper.getWorldEditPlugin(); + + Bukkit.getScheduler().runTaskTimer(Core.getInstance(), this::render, 20, 20); + } + + private void render() { + for(Player player : Bukkit.getOnlinePlayers()) { + if(player.getInventory().getItemInMainHand().getType() != WAND) + continue; + + LocalSession session = we.getSession(player); + try { + Clipboard clipboard = session.getClipboard().getClipboard(); + Vector pos = player.getLocation().toVector(); + Region region = clipboard.getRegion(); + Transform transform = session.getClipboard().getTransform(); + Vector a = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMinimum(region).subtract(WorldEditWrapper.impl.getOrigin(clipboard)), transform).add(pos); + Vector b = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMaximum(region).subtract(WorldEditWrapper.impl.getOrigin(clipboard)), transform).add(pos); + drawCuboid(Vector.getMinimum(a, b), Vector.getMaximum(a, b), TrickyParticleWrapper.impl.getVillagerHappy(), player); + } catch (EmptyClipboardException e) { + //ignore + } + + World world = session.getSelectionWorld(); + if(world != null) { + RegionSelector regionSelector = session.getRegionSelector(world); + try { + Region region = regionSelector.getRegion(); + drawCuboid(WorldEditWrapper.impl.getMinimum(region), WorldEditWrapper.impl.getMaximum(region), Particle.DRAGON_BREATH, player); + } catch (IncompleteRegionException e) { + //ignore + } + } + } + } + + private void drawCuboid(Vector min, Vector max, Particle particle, Player owner) { + max.add(ONES); + + for(double x = min.getBlockX(); x <= max.getBlockX(); x += STEP_SIZE) { + draw(x, min.getBlockY(), min.getBlockZ(), particle, owner); + draw(x, min.getBlockY(), max.getBlockZ(), particle, owner); + draw(x, max.getBlockY(), min.getBlockZ(), particle, owner); + draw(x, max.getBlockY(), max.getBlockZ(), particle, owner); + } + + for(double y = min.getBlockY() + STEP_SIZE; y <= max.getBlockY() - STEP_SIZE; y += STEP_SIZE) { + draw(min.getBlockX(), y, min.getBlockZ(), particle, owner); + draw(min.getBlockX(), y, max.getBlockZ(), particle, owner); + draw(max.getBlockX(), y, min.getBlockZ(), particle, owner); + draw(max.getBlockX(), y, max.getBlockZ(), particle, owner); + } + + for(double z = min.getBlockZ() + STEP_SIZE; z <= max.getBlockZ() - STEP_SIZE; z += STEP_SIZE) { + draw(min.getBlockX(), min.getBlockY(), z, particle, owner); + draw(min.getBlockX(), max.getBlockY(), z, particle, owner); + draw(max.getBlockX(), min.getBlockY(), z, particle, owner); + draw(max.getBlockX(), max.getBlockY(), z, particle, owner); + } + } + + private void draw(double x, double y, double z, Particle particle, Player owner) { + for(Player player : Bukkit.getOnlinePlayers()) { + Location location = player.getLocation(); + double dx = x - location.getX(); + double dy = y - location.getY(); + double dz = z - location.getZ(); + if(dx*dx + dy*dy + dz*dz > SQ_VIEW_DISTANCE) + continue; + + player.spawnParticle(player == owner ? particle : org.bukkit.Particle.TOWN_AURA, x, y, z, 1, 0.0, 0.0, 0.0, 0.0); + } + } +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java index 4e7b75761..24b207e89 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -102,8 +102,8 @@ public class Core extends JavaPlugin{ if(Core.getVersion() >= 19) new ServerDataHandler(); - if(Core.getVersion() > 8 && Bukkit.getPluginManager().getPlugin("WorldEdit") != null) - new WorldEditRenderer(); + if(Bukkit.getPluginManager().getPlugin("WorldEdit") != null) + WorldEditRenderer.impl.init(); Bukkit.getScheduler().runTaskTimer(this, TabCompletionCache::invalidateOldEntries, 20, 20); Bukkit.getScheduler().runTaskTimer(Core.getInstance(), SteamwarUser::clear, 72000, 72000); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java index 377efe137..6b90f1d23 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java @@ -1,126 +1,27 @@ /* - * This file is a part of the SteamWar software. + * This file is a part of the SteamWar software. * - * Copyright (C) 2024 SteamWar.de-Serverteam + * Copyright (C) 2020 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 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. + * 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 . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ package de.steamwar.core; -import com.sk89q.worldedit.EmptyClipboardException; -import com.sk89q.worldedit.IncompleteRegionException; -import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.bukkit.WorldEditPlugin; -import com.sk89q.worldedit.extent.clipboard.Clipboard; -import com.sk89q.worldedit.math.transform.Transform; -import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.regions.RegionSelector; -import com.sk89q.worldedit.world.World; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Particle; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; +public interface WorldEditRenderer { + WorldEditRenderer impl = VersionDependent.getVersionImpl(Core.getInstance()); -public class WorldEditRenderer { - - private static final int VIEW_DISTANCE = 64; - private static final int SQ_VIEW_DISTANCE = VIEW_DISTANCE * VIEW_DISTANCE; - - private static final double STEP_SIZE = 0.5; - - private static final Vector ONES = new Vector(1, 1, 1); - - private static final Material WAND = FlatteningWrapper.impl.getMaterial("WOOD_AXE"); - - private final WorldEditPlugin we; - - public WorldEditRenderer() { - we = WorldEditWrapper.getWorldEditPlugin(); - - Bukkit.getScheduler().runTaskTimer(Core.getInstance(), this::render, 20, 20); - } - - private void render() { - for(Player player : Bukkit.getOnlinePlayers()) { - //noinspection deprecation - if(player.getItemInHand().getType() != WAND) - continue; - - LocalSession session = we.getSession(player); - try { - Clipboard clipboard = session.getClipboard().getClipboard(); - Vector pos = player.getLocation().toVector(); - Region region = clipboard.getRegion(); - Transform transform = session.getClipboard().getTransform(); - Vector a = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMinimum(region).subtract(WorldEditWrapper.impl.getOrigin(clipboard)), transform).add(pos); - Vector b = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMaximum(region).subtract(WorldEditWrapper.impl.getOrigin(clipboard)), transform).add(pos); - drawCuboid(Vector.getMinimum(a, b), Vector.getMaximum(a, b), TrickyParticleWrapper.impl.getVillagerHappy(), player); - } catch (EmptyClipboardException e) { - //ignore - } - - World world = session.getSelectionWorld(); - if(world != null) { - RegionSelector regionSelector = session.getRegionSelector(world); - try { - Region region = regionSelector.getRegion(); - drawCuboid(WorldEditWrapper.impl.getMinimum(region), WorldEditWrapper.impl.getMaximum(region), Particle.DRAGON_BREATH, player); - } catch (IncompleteRegionException e) { - //ignore - } - } - } - } - - private void drawCuboid(Vector min, Vector max, Particle particle, Player owner) { - max.add(ONES); - - for(double x = min.getBlockX(); x <= max.getBlockX(); x += STEP_SIZE) { - draw(x, min.getBlockY(), min.getBlockZ(), particle, owner); - draw(x, min.getBlockY(), max.getBlockZ(), particle, owner); - draw(x, max.getBlockY(), min.getBlockZ(), particle, owner); - draw(x, max.getBlockY(), max.getBlockZ(), particle, owner); - } - - for(double y = min.getBlockY() + STEP_SIZE; y <= max.getBlockY() - STEP_SIZE; y += STEP_SIZE) { - draw(min.getBlockX(), y, min.getBlockZ(), particle, owner); - draw(min.getBlockX(), y, max.getBlockZ(), particle, owner); - draw(max.getBlockX(), y, min.getBlockZ(), particle, owner); - draw(max.getBlockX(), y, max.getBlockZ(), particle, owner); - } - - for(double z = min.getBlockZ() + STEP_SIZE; z <= max.getBlockZ() - STEP_SIZE; z += STEP_SIZE) { - draw(min.getBlockX(), min.getBlockY(), z, particle, owner); - draw(min.getBlockX(), max.getBlockY(), z, particle, owner); - draw(max.getBlockX(), min.getBlockY(), z, particle, owner); - draw(max.getBlockX(), max.getBlockY(), z, particle, owner); - } - } - - private void draw(double x, double y, double z, Particle particle, Player owner) { - for(Player player : Bukkit.getOnlinePlayers()) { - Location location = player.getLocation(); - double dx = x - location.getX(); - double dy = y - location.getY(); - double dz = z - location.getZ(); - if(dx*dx + dy*dy + dz*dz > SQ_VIEW_DISTANCE) - continue; - - player.spawnParticle(player == owner ? particle : Particle.TOWN_AURA, x, y, z, 1, 0.0, 0.0, 0.0, 0.0); - } + default void init() { } } From f6dc1e1059a0f5e665add244b39a5020263130a3 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Mon, 31 Mar 2025 19:24:30 +0200 Subject: [PATCH 059/153] Update WE version of 1.20 to FAWE 1.18 --- SpigotCore/SpigotCore_20/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore/SpigotCore_20/build.gradle.kts b/SpigotCore/SpigotCore_20/build.gradle.kts index 258086310..79f667e09 100644 --- a/SpigotCore/SpigotCore_20/build.gradle.kts +++ b/SpigotCore/SpigotCore_20/build.gradle.kts @@ -26,6 +26,6 @@ dependencies { compileOnly(libs.spigotapi) - compileOnly(libs.worldedit15) + compileOnly(libs.fawe18) compileOnly(libs.nms20) } From b10897c204c73663ec354615e48dd57b77ac2c07 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Tue, 15 Apr 2025 14:59:38 +0200 Subject: [PATCH 060/153] Update WorldEditRenderer --- .../de/steamwar/core/WorldEditRenderer20.java | 217 --------------- .../core/WorldEditRendererWrapper20.java | 145 +++++++++++ .../core/renderers/CuboidRegionRenderer.java | 159 ----------- .../core/WorldEditRendererWrapper8.java} | 29 +-- .../de/steamwar/core/WorldEditRenderer9.java | 125 --------- .../core/WorldEditRendererWrapper9.java | 80 ++++++ .../src/de/steamwar/core/Core.java | 50 +++- .../de/steamwar/core/VersionDependent.java | 10 +- .../de/steamwar/core/WorldEditRenderer.java | 169 ++++++++++-- .../core/WorldEditRendererWrapper.java | 47 ++++ .../src/de/steamwar/entity/CAABox.java | 103 ++++++++ .../src/de/steamwar/entity/CAALine.java | 246 ++++++++++++++++++ 12 files changed, 837 insertions(+), 543 deletions(-) delete mode 100644 SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRenderer20.java create mode 100644 SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java delete mode 100644 SpigotCore/SpigotCore_20/src/de/steamwar/core/renderers/CuboidRegionRenderer.java rename SpigotCore/{SpigotCore_20/src/de/steamwar/core/renderers/RegionRenderer.java => SpigotCore_8/src/de/steamwar/core/WorldEditRendererWrapper8.java} (50%) delete mode 100644 SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRenderer9.java create mode 100644 SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRendererWrapper9.java create mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererWrapper.java create mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CAABox.java create mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CAALine.java diff --git a/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRenderer20.java b/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRenderer20.java deleted file mode 100644 index d84f4abb5..000000000 --- a/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRenderer20.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 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.core; - -import com.sk89q.worldedit.EmptyClipboardException; -import com.sk89q.worldedit.IncompleteRegionException; -import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.bukkit.WorldEditPlugin; -import com.sk89q.worldedit.regions.CuboidRegion; -import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.regions.RegionSelector; -import com.sk89q.worldedit.world.World; -import de.steamwar.core.renderers.CuboidRegionRenderer; -import de.steamwar.core.renderers.RegionRenderer; -import de.steamwar.entity.REntityServer; -import org.bukkit.Bukkit; -import org.bukkit.Material; -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.BlockBreakEvent; -import org.bukkit.event.player.*; - -import java.util.HashMap; -import java.util.Map; -import java.util.function.Supplier; - -public class WorldEditRenderer20 implements WorldEditRenderer, Listener { - - private static final Map servers = new HashMap<>(); - private static final Map clipboards = new HashMap<>(); - private static final Map regionSelections = new HashMap<>(); - - private static final Material WAND = FlatteningWrapper.impl.getMaterial("WOOD_AXE"); - - private final WorldEditPlugin we; - - private static final Map, Supplier>> rendererMap = new HashMap<>(); - - static { - rendererMap.put(CuboidRegion.class, CuboidRegionRenderer::new); - } - - public WorldEditRenderer20() { - we = WorldEditWrapper.getWorldEditPlugin(); - Bukkit.getPluginManager().registerEvents(this, Core.getInstance()); - Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> { - for (Player player : Bukkit.getOnlinePlayers()) { - render(player); - } - }, 10, 10); - } - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onPlayerJoin(PlayerJoinEvent event) { - Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { - render(event.getPlayer()); - }, 0); - } - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) { - Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { - render(event.getPlayer()); - }, 0); - } - - @EventHandler - public void onPlayerDropItem(PlayerDropItemEvent event) { - Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { - render(event.getPlayer()); - }, 0); - } - - @EventHandler - public void onPlayerItemHeld(PlayerItemHeldEvent event) { - Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { - render(event.getPlayer()); - }, 0); - } - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onBlockBreak(BlockBreakEvent event) { - Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { - render(event.getPlayer()); - }, 0); - } - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onPlayerInteract(PlayerInteractEvent event) { - Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { - render(event.getPlayer()); - }, 0); - } - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onPlayerMove(PlayerMoveEvent event) { - Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { - render(event.getPlayer(), true, false); - }, 0); - } - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onPlayerQuit(PlayerQuitEvent event) { - REntityServer server = servers.remove(event.getPlayer()); - clipboards.remove(event.getPlayer()); - regionSelections.remove(event.getPlayer()); - if (server == null) return; - server.close(); - } - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { - String command = event.getMessage().split(" ")[0]; - command = command.replaceFirst("/", ""); - command = command.toLowerCase(); - if (WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().getCommandManager().containsCommand(command)) { - Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { - render(event.getPlayer()); - }, 10); - } - } - - private void render(Player player) { - render(player, true, true); - } - - private void render(Player player, boolean renderClipboard, boolean renderRegionSelection) { - if (player.getInventory().getItemInMainHand().getType() != WAND) { - REntityServer entityServer = servers.remove(player); - clipboards.remove(player); - regionSelections.remove(player); - if (entityServer != null) entityServer.close(); - return; - } - - REntityServer server = servers.computeIfAbsent(player, __ -> { - REntityServer _server = new REntityServer(); - _server.addPlayer(player); - return _server; - }); - - LocalSession session = we.getSession(player); - if (renderClipboard) { - renderClipboard(server, session, player); - } - if (renderRegionSelection) { - renderSelection(server, session, player); - } - } - - @SuppressWarnings("unchecked") - private void renderClipboard(REntityServer server, LocalSession session, Player player) { - try { - Region region = session.getClipboard().getClipboard().getRegion(); - clipboards.compute(player, (__, regionRenderer) -> { - if (regionRenderer != null && !regionRenderer.canDisplay(region)) { - regionRenderer.clear(); - regionRenderer = null; - } - if (regionRenderer == null) { - return rendererMap.getOrDefault(region.getClass(), RegionRenderer.NOOPImpl::new).get(); - } else { - return regionRenderer; - } - }).update(server, region, session.getClipboard(), Material.LIME_CONCRETE.createBlockData()); - } catch (EmptyClipboardException e) { - RegionRenderer regionRenderer = clipboards.remove(player); - if (regionRenderer != null) regionRenderer.clear(); - } - } - - @SuppressWarnings("unchecked") - private void renderSelection(REntityServer server, LocalSession session, Player player) { - World world = session.getSelectionWorld(); - if (world == null) { - return; - } - RegionSelector regionSelector = session.getRegionSelector(world); - try { - Region region = regionSelector.getRegion(); - regionSelections.compute(player, (__, regionRenderer) -> { - if (regionRenderer != null && !regionRenderer.canDisplay(region)) { - regionRenderer.clear(); - regionRenderer = null; - } - if (regionRenderer == null) { - return rendererMap.getOrDefault(region.getClass(), RegionRenderer.NOOPImpl::new).get(); - } else { - return regionRenderer; - } - }).update(server, region, null, Material.PURPLE_CONCRETE.createBlockData()); - } catch (IncompleteRegionException e) { - RegionRenderer regionRenderer = regionSelections.remove(player); - if (regionRenderer != null) regionRenderer.clear(); - } - } -} diff --git a/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java b/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java new file mode 100644 index 000000000..5bffe84f5 --- /dev/null +++ b/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java @@ -0,0 +1,145 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.core; + +import de.steamwar.entity.CAABox; +import de.steamwar.entity.CAALine; +import de.steamwar.entity.REntityServer; +import org.bukkit.Material; +import org.bukkit.block.data.BlockData; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +public class WorldEditRendererWrapper20 implements WorldEditRendererWrapper { + + private static final class BoxPair { + private CAABox regionBox; + private CAABox clipboardBox; + + public CAABox get(boolean clipboard) { + if (clipboard) { + return clipboardBox; + } else { + return regionBox; + } + } + + public void set(boolean clipboard, CAABox box) { + if (clipboard) { + this.clipboardBox = box; + } else { + this.regionBox = box; + } + } + + public void die() { + if (clipboardBox != null) { + clipboardBox.die(); + } + if (regionBox != null) { + regionBox.die(); + } + } + } + + private static final Map servers = new HashMap<>(); + private static final Map> boxes = new HashMap<>(); + + @Override + public void draw(Player player, Player owner, boolean clipboard, Vector pos1, Vector pos2) { + REntityServer server = servers.computeIfAbsent(player, __ -> { + REntityServer entityServer = new REntityServer(); + entityServer.addPlayer(player); + return entityServer; + }); + + float width = CAALine.DEFAULT_WIDTH; + if (player != owner) { + width = 1 / 64f; + } + + BlockData block; + if (player == owner) { + if (clipboard) { + block = Material.LIME_CONCRETE.createBlockData(); + } else { + block = Material.PURPLE_CONCRETE.createBlockData(); + } + } else { + block = Material.GRAY_CONCRETE.createBlockData(); + } + + BoxPair boxPair = boxes.computeIfAbsent(player, __ -> new HashMap<>()).computeIfAbsent(owner, __ -> new BoxPair()); + CAABox box = boxPair.get(clipboard); + if (box == null) { + box = new CAABox(server); + boxPair.set(clipboard, box); + } + box.setPos1(null).setPos2(null); + box.setPos1(pos1.toLocation(player.getWorld())); + box.setPos2(pos2.toLocation(player.getWorld())); + box.setWidth(width); + box.setBlock(block); + } + + @Override + public void tick(Player player) { + REntityServer server = servers.get(player); + if (server != null) server.tick(); + } + + @Override + public void hide(Player player, Player owner, boolean clipboard, boolean hide) { + Map pairs = boxes.getOrDefault(player, Collections.emptyMap()); + if (owner != null) { + BoxPair boxPair = pairs.get(owner); + if (boxPair == null) return; + CAABox box = boxPair.get(clipboard); + if (box != null) box.hide(hide); + } else { + pairs.values().forEach(boxPair -> { + CAABox box = boxPair.get(clipboard); + if (box != null) box.hide(hide); + }); + } + } + + @Override + public void remove(Player player) { + Map removed = boxes.remove(player); + if (removed != null) { + removed.values().forEach(boxPair -> { + boxPair.die(); + }); + } + boxes.values().forEach(map -> { + BoxPair boxPair = map.remove(player); + if (boxPair == null) return; + boxPair.die(); + }); + + REntityServer server = servers.remove(player); + if (server != null) server.close(); + } +} diff --git a/SpigotCore/SpigotCore_20/src/de/steamwar/core/renderers/CuboidRegionRenderer.java b/SpigotCore/SpigotCore_20/src/de/steamwar/core/renderers/CuboidRegionRenderer.java deleted file mode 100644 index 70391d3db..000000000 --- a/SpigotCore/SpigotCore_20/src/de/steamwar/core/renderers/CuboidRegionRenderer.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 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.core.renderers; - -import com.sk89q.worldedit.math.transform.Transform; -import com.sk89q.worldedit.regions.CuboidRegion; -import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.session.ClipboardHolder; -import de.steamwar.core.WorldEditWrapper; -import de.steamwar.entity.RBlockDisplay; -import de.steamwar.entity.REntityServer; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.block.data.BlockData; -import org.bukkit.entity.Display; -import org.bukkit.entity.Player; -import org.bukkit.util.Transformation; -import org.bukkit.util.Vector; -import org.joml.Quaternionf; -import org.joml.Vector3f; - -public class CuboidRegionRenderer implements RegionRenderer { - - private static final World WORLD = Bukkit.getWorlds().get(0); - private static final float offset = 1 / 1024f; - private static final float width = 1 / 16f; - - private Vector lastA = null; - private Vector lastB = null; - - private RBlockDisplay bd01; - private RBlockDisplay bd02; - private RBlockDisplay bd03; - private RBlockDisplay bd04; - private RBlockDisplay bd05; - private RBlockDisplay bd06; - private RBlockDisplay bd07; - private RBlockDisplay bd08; - private RBlockDisplay bd09; - private RBlockDisplay bd10; - private RBlockDisplay bd11; - private RBlockDisplay bd12; - - @Override - public boolean canDisplay(Region region) { - return region instanceof CuboidRegion; - } - - public void update(REntityServer server, CuboidRegion region, ClipboardHolder holder, BlockData block) { - Vector a; - Vector b; - if (holder != null) { - Player player = server.getPlayers().stream().findFirst().orElse(null); - if (player == null) return; - Vector pos = player.getLocation().toVector(); - Transform transform = holder.getTransform(); - a = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMinimum(region).subtract(WorldEditWrapper.impl.getOrigin(holder.getClipboard())), transform).add(pos); - b = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMaximum(region).subtract(WorldEditWrapper.impl.getOrigin(holder.getClipboard())), transform).add(pos); - } else { - a = WorldEditWrapper.impl.getMinimum(region); - b = WorldEditWrapper.impl.getMaximum(region); - } - - if (a.equals(lastA) && b.equals(lastB)) { - return; - } - - drawCuboid(server, toBlockVector(a), toBlockVector(b), block); - } - - @Override - public void clear() { - if (bd01 != null) bd01.die(); - if (bd02 != null) bd02.die(); - if (bd03 != null) bd03.die(); - if (bd04 != null) bd04.die(); - if (bd05 != null) bd05.die(); - if (bd06 != null) bd06.die(); - if (bd07 != null) bd07.die(); - if (bd08 != null) bd08.die(); - if (bd09 != null) bd09.die(); - if (bd10 != null) bd10.die(); - if (bd11 != null) bd11.die(); - if (bd12 != null) bd12.die(); - } - - private void drawCuboid(REntityServer server, Vector min, Vector max, BlockData block) { - max.add(new Vector(1 - width, 1 - width, 1 - width)); - - bd01 = drawLine(bd01, server, new Vector(min.getX() - offset, min.getY(), min.getZ()), new Vector(max.getX() + width, min.getY(), min.getZ()), block); - bd02 = drawLine(bd02, server, new Vector(min.getX() - offset, max.getY(), min.getZ()), new Vector(max.getX() + width, max.getY(), min.getZ()), block); - bd03 = drawLine(bd03, server, new Vector(min.getX() - offset, min.getY(), max.getZ()), new Vector(max.getX() + width, min.getY(), max.getZ()), block); - bd04 = drawLine(bd04, server, new Vector(min.getX() - offset, max.getY(), max.getZ()), new Vector(max.getX() + width, max.getY(), max.getZ()), block); - - bd05 = drawLine(bd05, server, new Vector(min.getX(), min.getY() - offset, min.getZ()), new Vector(min.getX(), max.getY() + width, min.getZ()), block); - bd06 = drawLine(bd06, server, new Vector(max.getX(), min.getY() - offset, min.getZ()), new Vector(max.getX(), max.getY() + width, min.getZ()), block); - bd07 = drawLine(bd07, server, new Vector(min.getX(), min.getY() - offset, max.getZ()), new Vector(min.getX(), max.getY() + width, max.getZ()), block); - bd08 = drawLine(bd08, server, new Vector(max.getX(), min.getY() - offset, max.getZ()), new Vector(max.getX(), max.getY() + width, max.getZ()), block); - - bd09 = drawLine(bd09, server, new Vector(min.getX(), min.getY(), min.getZ() - offset), new Vector(min.getX(), min.getY(), max.getZ() + width), block); - bd10 = drawLine(bd10, server, new Vector(max.getX(), min.getY(), min.getZ() - offset), new Vector(max.getX(), min.getY(), max.getZ() + width), block); - bd11 = drawLine(bd11, server, new Vector(min.getX(), max.getY(), min.getZ() - offset), new Vector(min.getX(), max.getY(), max.getZ() + width), block); - bd12 = drawLine(bd12, server, new Vector(max.getX(), max.getY(), min.getZ() - offset), new Vector(max.getX(), max.getY(), max.getZ() + width), block); - } - - private RBlockDisplay drawLine(RBlockDisplay display, REntityServer server, Vector from, Vector to, BlockData block) { - Location spawnLocation = from.clone().add(to).divide(new Vector(2, 2, 2)).toLocation(WORLD); - if (display == null) { - display = new RBlockDisplay(server, spawnLocation); - } - - Vector vector = to.clone().subtract(from); - if (vector.getX() == 0) { - vector.setX(vector.getX() + width + offset * 2); - } - if (vector.getY() == 0) { - vector.setY(vector.getY() + width + offset * 2); - } - if (vector.getZ() == 0) { - vector.setZ(vector.getZ() + width + offset * 2); - } - - Vector transformVec = from.subtract(spawnLocation.toVector()); - transformVec.subtract(new Vector(offset, offset, offset)); - - display.setTransform(new Transformation(toVec3f(transformVec), new Quaternionf(0, 0, 0, 1), toVec3f(vector), new Quaternionf(0, 0, 0, 1))); - display.setBrightness(new Display.Brightness(15, 15)); - display.setBlock(block); - display.move(spawnLocation); - - return display; - } - - private Vector toBlockVector(Vector vector) { - return new Vector(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); - } - - private Vector3f toVec3f(Vector vector) { - return new Vector3f((float) vector.getX(), (float) vector.getY(), (float) vector.getZ()); - } -} diff --git a/SpigotCore/SpigotCore_20/src/de/steamwar/core/renderers/RegionRenderer.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditRendererWrapper8.java similarity index 50% rename from SpigotCore/SpigotCore_20/src/de/steamwar/core/renderers/RegionRenderer.java rename to SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditRendererWrapper8.java index 53121deb2..1ca68b2d7 100644 --- a/SpigotCore/SpigotCore_20/src/de/steamwar/core/renderers/RegionRenderer.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditRendererWrapper8.java @@ -17,31 +17,14 @@ * along with this program. If not, see . */ -package de.steamwar.core.renderers; +package de.steamwar.core; -import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.session.ClipboardHolder; -import de.steamwar.entity.REntityServer; -import org.bukkit.block.data.BlockData; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; -public interface RegionRenderer { +public class WorldEditRendererWrapper8 implements WorldEditRendererWrapper { - boolean canDisplay(Region region); - void update(REntityServer server, R region, ClipboardHolder holder, BlockData block); - void clear(); - - final class NOOPImpl implements RegionRenderer { - @Override - public boolean canDisplay(Region region) { - return false; - } - - @Override - public void update(REntityServer server, Region region, ClipboardHolder holder, BlockData block) { - } - - @Override - public void clear() { - } + @Override + public void draw(Player player, Player owner, boolean clipboard, Vector pos1, Vector pos2) { } } diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRenderer9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRenderer9.java deleted file mode 100644 index 971a759c7..000000000 --- a/SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRenderer9.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 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.core; - -import com.sk89q.worldedit.EmptyClipboardException; -import com.sk89q.worldedit.IncompleteRegionException; -import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.bukkit.WorldEditPlugin; -import com.sk89q.worldedit.extent.clipboard.Clipboard; -import com.sk89q.worldedit.math.transform.Transform; -import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.regions.RegionSelector; -import com.sk89q.worldedit.world.World; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Particle; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -public class WorldEditRenderer9 implements WorldEditRenderer { - - private static final int VIEW_DISTANCE = 64; - private static final int SQ_VIEW_DISTANCE = VIEW_DISTANCE * VIEW_DISTANCE; - - private static final double STEP_SIZE = 0.5; - - private static final Vector ONES = new Vector(1, 1, 1); - - private static final Material WAND = FlatteningWrapper.impl.getMaterial("WOOD_AXE"); - - private final WorldEditPlugin we; - - public WorldEditRenderer9() { - we = WorldEditWrapper.getWorldEditPlugin(); - - Bukkit.getScheduler().runTaskTimer(Core.getInstance(), this::render, 20, 20); - } - - private void render() { - for(Player player : Bukkit.getOnlinePlayers()) { - if(player.getInventory().getItemInMainHand().getType() != WAND) - continue; - - LocalSession session = we.getSession(player); - try { - Clipboard clipboard = session.getClipboard().getClipboard(); - Vector pos = player.getLocation().toVector(); - Region region = clipboard.getRegion(); - Transform transform = session.getClipboard().getTransform(); - Vector a = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMinimum(region).subtract(WorldEditWrapper.impl.getOrigin(clipboard)), transform).add(pos); - Vector b = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMaximum(region).subtract(WorldEditWrapper.impl.getOrigin(clipboard)), transform).add(pos); - drawCuboid(Vector.getMinimum(a, b), Vector.getMaximum(a, b), TrickyParticleWrapper.impl.getVillagerHappy(), player); - } catch (EmptyClipboardException e) { - //ignore - } - - World world = session.getSelectionWorld(); - if(world != null) { - RegionSelector regionSelector = session.getRegionSelector(world); - try { - Region region = regionSelector.getRegion(); - drawCuboid(WorldEditWrapper.impl.getMinimum(region), WorldEditWrapper.impl.getMaximum(region), Particle.DRAGON_BREATH, player); - } catch (IncompleteRegionException e) { - //ignore - } - } - } - } - - private void drawCuboid(Vector min, Vector max, Particle particle, Player owner) { - max.add(ONES); - - for(double x = min.getBlockX(); x <= max.getBlockX(); x += STEP_SIZE) { - draw(x, min.getBlockY(), min.getBlockZ(), particle, owner); - draw(x, min.getBlockY(), max.getBlockZ(), particle, owner); - draw(x, max.getBlockY(), min.getBlockZ(), particle, owner); - draw(x, max.getBlockY(), max.getBlockZ(), particle, owner); - } - - for(double y = min.getBlockY() + STEP_SIZE; y <= max.getBlockY() - STEP_SIZE; y += STEP_SIZE) { - draw(min.getBlockX(), y, min.getBlockZ(), particle, owner); - draw(min.getBlockX(), y, max.getBlockZ(), particle, owner); - draw(max.getBlockX(), y, min.getBlockZ(), particle, owner); - draw(max.getBlockX(), y, max.getBlockZ(), particle, owner); - } - - for(double z = min.getBlockZ() + STEP_SIZE; z <= max.getBlockZ() - STEP_SIZE; z += STEP_SIZE) { - draw(min.getBlockX(), min.getBlockY(), z, particle, owner); - draw(min.getBlockX(), max.getBlockY(), z, particle, owner); - draw(max.getBlockX(), min.getBlockY(), z, particle, owner); - draw(max.getBlockX(), max.getBlockY(), z, particle, owner); - } - } - - private void draw(double x, double y, double z, Particle particle, Player owner) { - for(Player player : Bukkit.getOnlinePlayers()) { - Location location = player.getLocation(); - double dx = x - location.getX(); - double dy = y - location.getY(); - double dz = z - location.getZ(); - if(dx*dx + dy*dy + dz*dz > SQ_VIEW_DISTANCE) - continue; - - player.spawnParticle(player == owner ? particle : org.bukkit.Particle.TOWN_AURA, x, y, z, 1, 0.0, 0.0, 0.0, 0.0); - } - } -} diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRendererWrapper9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRendererWrapper9.java new file mode 100644 index 000000000..6a06be458 --- /dev/null +++ b/SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRendererWrapper9.java @@ -0,0 +1,80 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.core; + +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +public class WorldEditRendererWrapper9 implements WorldEditRendererWrapper { + + private static final int VIEW_DISTANCE = 64; + private static final int SQ_VIEW_DISTANCE = VIEW_DISTANCE * VIEW_DISTANCE; + + private static final double STEP_SIZE = 0.5; + private static final Vector ONES = new Vector(1, 1, 1); + private static final Vector STEPS = new Vector(STEP_SIZE, STEP_SIZE, STEP_SIZE); + + @Override + public void draw(Player player, Player owner, boolean clipboard, Vector min, Vector max) { + max = max.clone().add(ONES); + drawLine(player, owner, clipboard, new Vector(min.getX(), min.getY(), min.getZ()), new Vector(max.getX(), min.getY(), min.getZ())); + drawLine(player, owner, clipboard, new Vector(min.getX(), max.getY(), min.getZ()), new Vector(max.getX(), max.getY(), min.getZ())); + drawLine(player, owner, clipboard, new Vector(min.getX(), min.getY(), max.getZ()), new Vector(max.getX(), min.getY(), max.getZ())); + drawLine(player, owner, clipboard, new Vector(min.getX(), max.getY(), max.getZ()), new Vector(max.getX(), max.getY(), max.getZ())); + + drawLine(player, owner, clipboard, new Vector(min.getX(), min.getY(), min.getZ()), new Vector(min.getX(), max.getY(), min.getZ())); + drawLine(player, owner, clipboard, new Vector(max.getX(), min.getY(), min.getZ()), new Vector(max.getX(), max.getY(), min.getZ())); + drawLine(player, owner, clipboard, new Vector(min.getX(), min.getY(), max.getZ()), new Vector(min.getX(), max.getY(), max.getZ())); + drawLine(player, owner, clipboard, new Vector(max.getX(), min.getY(), max.getZ()), new Vector(max.getX(), max.getY(), max.getZ())); + + drawLine(player, owner, clipboard, new Vector(min.getX(), min.getY(), min.getZ()), new Vector(min.getX(), min.getY(), max.getZ())); + drawLine(player, owner, clipboard, new Vector(max.getX(), min.getY(), min.getZ()), new Vector(max.getX(), min.getY(), max.getZ())); + drawLine(player, owner, clipboard, new Vector(min.getX(), max.getY(), min.getZ()), new Vector(min.getX(), max.getY(), max.getZ())); + drawLine(player, owner, clipboard, new Vector(max.getX(), max.getY(), min.getZ()), new Vector(max.getX(), max.getY(), max.getZ())); + } + + public void drawLine(Player player, Player owner, boolean clipboard, Vector min, Vector max) { + Particle particle; + if (player == owner) { + if (clipboard) { + particle = TrickyParticleWrapper.impl.getVillagerHappy(); + } else { + particle = Particle.DRAGON_BREATH; + } + } else { + particle = Particle.TOWN_AURA; + } + + Vector stepSize = max.clone().subtract(min).normalize().multiply(STEPS); + while (min.getX() <= max.getX() && min.getY() <= max.getY() && min.getZ() <= max.getZ()) { + Location location = player.getLocation(); + double dx = min.getX() - location.getX(); + double dy = min.getY() - location.getY(); + double dz = min.getZ() - location.getZ(); + if (dx * dx + dy * dy + dz * dz > SQ_VIEW_DISTANCE) + continue; + + player.spawnParticle(particle, min.getX(), min.getY(), min.getZ(), 1, 0.0, 0.0, 0.0, 0.0); + min.add(stepSize); + } + } +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java index 24b207e89..ca2467b38 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -20,10 +20,15 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.TinyProtocol; +import com.google.gson.Gson; +import com.google.gson.JsonObject; import de.steamwar.Reflection; import de.steamwar.command.*; import de.steamwar.core.authlib.AuthlibInjector; -import de.steamwar.core.events.*; +import de.steamwar.core.events.AntiNocom; +import de.steamwar.core.events.ChattingEvent; +import de.steamwar.core.events.PlayerJoinedEvent; +import de.steamwar.core.events.WorldLoadEvent; import de.steamwar.message.Message; import de.steamwar.network.NetworkReceiver; import de.steamwar.network.handlers.ServerDataHandler; @@ -32,23 +37,42 @@ import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.internal.Statement; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.plugin.messaging.PluginMessageListener; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Collection; +import java.util.HashMap; +import java.util.Map; import java.util.logging.Level; -public class Core extends JavaPlugin{ +public class Core extends JavaPlugin implements PluginMessageListener, Listener { public static final Message MESSAGE = new Message("SpigotCore", Core.class.getClassLoader()); + private static final String CHANNEL = "vv:proxy_details"; + private static final Gson GSON = new Gson(); + private static final Map playerVersions = new HashMap<>(); + public static int getVersion(){ return Reflection.MAJOR_VERSION; } + public static int getPlayerVersion(Player player) { + return playerVersions.getOrDefault(player, -1); + } + + public static boolean isBedrockPlayer(Player player) { + return player.getName().startsWith("."); + } + private static JavaPlugin instance; public static JavaPlugin getInstance() { return instance; @@ -67,6 +91,9 @@ public class Core extends JavaPlugin{ @Override public void onEnable() { + this.getServer().getMessenger().registerIncomingPluginChannel(this, CHANNEL, this); + Bukkit.getPluginManager().registerEvents(this, this); + errorHandler = new ErrorHandler(); crashDetector = new CrashDetector(); @@ -103,7 +130,7 @@ public class Core extends JavaPlugin{ new ServerDataHandler(); if(Bukkit.getPluginManager().getPlugin("WorldEdit") != null) - WorldEditRenderer.impl.init(); + new WorldEditRenderer(); Bukkit.getScheduler().runTaskTimer(this, TabCompletionCache::invalidateOldEntries, 20, 20); Bukkit.getScheduler().runTaskTimer(Core.getInstance(), SteamwarUser::clear, 72000, 72000); @@ -122,5 +149,22 @@ public class Core extends JavaPlugin{ errorHandler.unregister(); if(crashDetector.onMainThread()) Statement.closeAll(); + this.getServer().getMessenger().unregisterIncomingPluginChannel(this); + } + + @Override + public void onPluginMessageReceived(String channel, Player player, byte[] bytes) { + if (!channel.equals(CHANNEL)) { + return; + } + + final JsonObject payload = GSON.fromJson(new String(bytes), JsonObject.class); + final String version = payload.get("versionName").getAsString(); + playerVersions.put(player, Integer.parseInt(version.split("-")[0].split("\\.")[1])); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onPlayerQuit(PlayerQuitEvent event) { + playerVersions.remove(event.getPlayer()); } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/VersionDependent.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/VersionDependent.java index 5e8ec241d..2fe94ce55 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/VersionDependent.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/VersionDependent.java @@ -31,8 +31,16 @@ public class VersionDependent { } public static T getVersionImpl(Plugin plugin, String className){ + return getVersionImpl(plugin, Core.getVersion(), className); + } + + public static T getVersionImpl(Plugin plugin, int fromVersion){ + return getVersionImpl(plugin, fromVersion, (new Exception()).getStackTrace()[1].getClassName()); + } + + public static T getVersionImpl(Plugin plugin, int fromVersion, String className){ ClassLoader loader = plugin.getClass().getClassLoader(); - for(int version = Core.getVersion(); version >= 8; version--) { + for(int version = fromVersion; version >= 8; version--) { try { return ((Class) Class.forName(className + version, true, loader)).getDeclaredConstructor().newInstance(); } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java index 6b90f1d23..7bf68c99b 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java @@ -1,27 +1,166 @@ /* - * This file is a part of the SteamWar software. + * This file is a part of the SteamWar software. * - * Copyright (C) 2020 SteamWar.de-Serverteam + * Copyright (C) 2024 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 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. + * 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 . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ package de.steamwar.core; -public interface WorldEditRenderer { - WorldEditRenderer impl = VersionDependent.getVersionImpl(Core.getInstance()); +import com.sk89q.worldedit.EmptyClipboardException; +import com.sk89q.worldedit.IncompleteRegionException; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.math.transform.Transform; +import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.regions.RegionSelector; +import com.sk89q.worldedit.world.World; +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.block.BlockBreakEvent; +import org.bukkit.event.player.*; +import org.bukkit.util.Vector; - default void init() { +public class WorldEditRenderer implements Listener { + + private static final Material WAND = FlatteningWrapper.impl.getMaterial("WOOD_AXE"); + + private final WorldEditPlugin we; + + public WorldEditRenderer() { + we = WorldEditWrapper.getWorldEditPlugin(); + Bukkit.getPluginManager().registerEvents(this, Core.getInstance()); + + Bukkit.getScheduler().runTaskTimer(Core.getInstance(), this::render, 20, 20); + } + + private void render() { + for(Player player : Bukkit.getOnlinePlayers()) { + renderPlayer(player); + } + } + + private void renderPlayer(Player player) { + LocalSession session = we.getSession(player); + renderClipboard(player, session); + renderRegion(player, session); + } + + private void renderClipboard(Player player, LocalSession session) { + try { + Clipboard clipboard = session.getClipboard().getClipboard(); + Vector pos = player.getLocation().toVector(); + Region region = clipboard.getRegion(); + Transform transform = session.getClipboard().getTransform(); + Vector a = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMinimum(region).subtract(WorldEditWrapper.impl.getOrigin(clipboard)), transform).add(pos); + Vector b = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMaximum(region).subtract(WorldEditWrapper.impl.getOrigin(clipboard)), transform).add(pos); + a = new Vector(a.getBlockX(), a.getBlockY(), a.getBlockZ()); + b = new Vector(b.getBlockX(), b.getBlockY(), b.getBlockZ()); + WorldEditRendererWrapper.impl.hide(player, player, true, false); + drawCuboid(Vector.getMinimum(a, b), Vector.getMaximum(a, b), true, player); + } catch (EmptyClipboardException e) { + WorldEditRendererWrapper.impl.hide(player, player, true, true); + } + } + + private void renderRegion(Player player, LocalSession session) { + World world = session.getSelectionWorld(); + if(world != null) { + RegionSelector regionSelector = session.getRegionSelector(world); + try { + Region region = regionSelector.getRegion(); + WorldEditRendererWrapper.impl.hide(player, player, false, false); + drawCuboid(WorldEditWrapper.impl.getMinimum(region), WorldEditWrapper.impl.getMaximum(region), false, player); + } catch (IncompleteRegionException e) { + WorldEditRendererWrapper.impl.hide(player, player, false, true); + } + } + } + + private void drawCuboid(Vector min, Vector max, boolean clipboard, Player owner) { + for (Player player : Bukkit.getOnlinePlayers()) { + //noinspection deprecation + if(player.getItemInHand().getType() != WAND) { + WorldEditRendererWrapper.impl.hide(player, owner, true, true); + WorldEditRendererWrapper.impl.hide(player, owner, false, true); + } else { + WorldEditRendererWrapper.impl.hide(player, owner, true, false); + WorldEditRendererWrapper.impl.hide(player, owner, false, false); + WorldEditRendererWrapper.safeDraw(player, owner, clipboard, min, max); + } + } + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + renderPlayer(event.getPlayer()); + } + + @EventHandler + public void onPlayerMove(PlayerMoveEvent event) { + WorldEditRendererWrapper.impl.tick(event.getPlayer()); + + renderClipboard(event.getPlayer(), we.getSession(event.getPlayer())); + } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + renderRegion(event.getPlayer(), we.getSession(event.getPlayer())); + } + + @EventHandler + public void onBlockBreak(BlockBreakEvent event) { + renderRegion(event.getPlayer(), we.getSession(event.getPlayer())); + } + + @EventHandler + public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { + if (event.getMessage().startsWith("//")) { + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { + LocalSession session = we.getSession(event.getPlayer()); + renderRegion(event.getPlayer(), session); + renderClipboard(event.getPlayer(), session); + }, 5); + } + } + + @EventHandler + public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) { + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { + renderPlayer(event.getPlayer()); + }, 1); + } + + @EventHandler + public void onPlayerDropItem(PlayerDropItemEvent event) { + renderPlayer(event.getPlayer()); + } + + @EventHandler + public void onPlayerItemHeld(PlayerItemHeldEvent event) { + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { + renderPlayer(event.getPlayer()); + }, 1); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + WorldEditRendererWrapper.impl.remove(event.getPlayer()); } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererWrapper.java new file mode 100644 index 000000000..63380fdcd --- /dev/null +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererWrapper.java @@ -0,0 +1,47 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.core; + +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +public interface WorldEditRendererWrapper { + WorldEditRendererWrapper fallback = VersionDependent.getVersionImpl(Core.getInstance(), 9); + WorldEditRendererWrapper impl = VersionDependent.getVersionImpl(Core.getInstance()); + + static void safeDraw(Player player, Player owner, boolean clipboard, Vector pos1, Vector pos2) { + if (Core.isBedrockPlayer(player) || Core.getPlayerVersion(player) < 20) { + fallback.draw(player, owner, clipboard, pos1, pos2); + } else { + impl.draw(player, owner, clipboard, pos1, pos2); + } + } + + void draw(Player player, Player owner, boolean clipboard, Vector pos1, Vector pos2); + + default void tick(Player player) { + } + + default void hide(Player player, Player owner, boolean clipboard, boolean hide) { + } + + default void remove(Player player) { + } +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CAABox.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CAABox.java new file mode 100644 index 000000000..80d94c88f --- /dev/null +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CAABox.java @@ -0,0 +1,103 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.entity; + +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.data.BlockData; +import org.bukkit.util.Vector; + +import java.util.List; + +/** + * Compound Axis Aligned Box (12 CAALine) + */ +public class CAABox extends CEntity { + + public static final float DEFAULT_WIDTH = 1 / 16f; + private float width = DEFAULT_WIDTH; + + private Location pos1; + private Location pos2; + + public CAABox(REntityServer server) { + super(server); + } + + public CAABox setPos1(Location pos1) { + this.pos1 = pos1; + updateAndSpawnLines(); + return this; + } + + public CAABox setPos2(Location pos2) { + this.pos2 = pos2; + updateAndSpawnLines(); + return this; + } + + public CAABox setWidth(float width) { + this.width = width; + updateAndSpawnLines(); + getEntitiesByType(CAALine.class).forEach(haaLine -> { + haaLine.setWidth(width); + }); + return this; + } + + public CAABox setBlock(BlockData blockData) { + getEntitiesByType(CAALine.class).forEach(haaLine -> { + haaLine.setBlock(blockData); + }); + return this; + } + + private void updateAndSpawnLines() { + if (pos1 == null || pos2 == null) return; + if (entities.isEmpty()) { + for (int i = 0; i < 12; i++) { + entities.add(new CAALine(server)); + } + } + + World world = pos1.getWorld(); + Vector min = Vector.getMinimum(pos1.toVector(), pos2.toVector()); + Vector max = Vector.getMaximum(pos1.toVector(), pos2.toVector()) + .add(new Vector(1 - width, 1 - width, 1 - width)); + + List lines = getEntitiesByType(CAALine.class); + lines.forEach(line -> line.setFrom(null).setTo(null)); + + lines.get(0).setFrom(new Vector(min.getX(), min.getY(), min.getZ()).toLocation(world)).setTo(new Vector(max.getX() + width, min.getY(), min.getZ()).toLocation(world)); + lines.get(1).setFrom(new Vector(min.getX(), max.getY(), min.getZ()).toLocation(world)).setTo(new Vector(max.getX() + width, max.getY(), min.getZ()).toLocation(world)); + lines.get(2).setFrom(new Vector(min.getX(), min.getY(), max.getZ()).toLocation(world)).setTo(new Vector(max.getX() + width, min.getY(), max.getZ()).toLocation(world)); + lines.get(3).setFrom(new Vector(min.getX(), max.getY(), max.getZ()).toLocation(world)).setTo(new Vector(max.getX() + width, max.getY(), max.getZ()).toLocation(world)); + + lines.get(4).setFrom(new Vector(min.getX(), min.getY(), min.getZ()).toLocation(world)).setTo(new Vector(min.getX(), max.getY() + width, min.getZ()).toLocation(world)); + lines.get(5).setFrom(new Vector(max.getX(), min.getY(), min.getZ()).toLocation(world)).setTo(new Vector(max.getX(), max.getY() + width, min.getZ()).toLocation(world)); + lines.get(6).setFrom(new Vector(min.getX(), min.getY(), max.getZ()).toLocation(world)).setTo(new Vector(min.getX(), max.getY() + width, max.getZ()).toLocation(world)); + lines.get(7).setFrom(new Vector(max.getX(), min.getY(), max.getZ()).toLocation(world)).setTo(new Vector(max.getX(), max.getY() + width, max.getZ()).toLocation(world)); + + lines.get(8).setFrom(new Vector(min.getX(), min.getY(), min.getZ()).toLocation(world)).setTo(new Vector(min.getX(), min.getY(), max.getZ() + width).toLocation(world)); + lines.get(9).setFrom(new Vector(max.getX(), min.getY(), min.getZ()).toLocation(world)).setTo(new Vector(max.getX(), min.getY(), max.getZ() + width).toLocation(world)); + lines.get(10).setFrom(new Vector(min.getX(), max.getY(), min.getZ()).toLocation(world)).setTo(new Vector(min.getX(), max.getY(), max.getZ() + width).toLocation(world)); + lines.get(11).setFrom(new Vector(max.getX(), max.getY(), min.getZ()).toLocation(world)).setTo(new Vector(max.getX(), max.getY(), max.getZ() + width).toLocation(world)); + } +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CAALine.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CAALine.java new file mode 100644 index 000000000..19a6ef9f8 --- /dev/null +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CAALine.java @@ -0,0 +1,246 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.entity; + +import org.bukkit.Location; +import org.bukkit.block.data.BlockData; +import org.bukkit.entity.Display; +import org.bukkit.entity.Player; +import org.bukkit.util.Transformation; +import org.bukkit.util.Vector; +import org.joml.Quaternionf; +import org.joml.Vector3f; + +import java.util.Objects; + +public class CAALine extends CEntity { + + public static final float DEFAULT_WIDTH = 1 / 16f; + private static final float offset = 1 / 1024f; + private static final Vector offsetVec = new Vector(offset, offset, offset); + + private Location from; + private Location to; + private float width = DEFAULT_WIDTH; + private BlockData blockData = RBlockDisplay.DEFAULT_BLOCK; + + public CAALine(REntityServer server) { + super(server); + tick(); + } + + public CAALine setFrom(Location from) { + if (Objects.equals(from, this.from)) return this; + this.from = from; + tick(); + return this; + } + + public CAALine setTo(Location to) { + if (Objects.equals(to, this.to)) return this; + this.to = to; + tick(); + return this; + } + + public CAALine setWidth(float width) { + if (this.width == width) return this; + this.width = width; + tick(); + return this; + } + + public CAALine setBlock(BlockData blockData) { + if (this.blockData.equals(blockData)) return this; + if (blockData == null) { + this.blockData = RBlockDisplay.DEFAULT_BLOCK; + } else { + this.blockData = blockData; + } + getEntitiesByType(RBlockDisplay.class).forEach(display -> { + display.setBlock(blockData); + }); + return this; + } + + private boolean hide = false; + + @Override + public void hide(boolean hide) { + if (hide == this.hide) return; + this.hide = hide; + if (hide) { + if (startLine != null) startLine.hide(true); + if (middleLine != null) middleLine.hide(true); + if (endLine != null) endLine.hide(true); + } else { + tick(); + } + } + + @Override + void tick() { + if (from == null || to == null) return; + if (hide) return; + updateStart(); + updateMiddle(); + updateEnd(); + } + + private RBlockDisplay startLine; + private void updateStart() { + Vector vec = to.clone().subtract(from).toVector(); + if (vec.length() > 35) vec.normalize().multiply(35); + + if (startLine == null) { + startLine = new RBlockDisplay(server, new Location(null, 0, 0, 0)); + startLine.setBrightness(new Display.Brightness(15, 15)); + startLine.setViewRange(560); + startLine.setBlock(blockData); + entities.add(startLine); + } else { + startLine.hide(false); + } + + startLine.move(from.clone().subtract(offsetVec)); + startLine.setTransform(new Transformation(new Vector3f(0, 0, 0), new Quaternionf(0, 0, 0, 1), addWidth(vec).toVector3f(), new Quaternionf(0, 0, 0, 1))); + } + + private RBlockDisplay middleLine; + private void updateMiddle() { + Vector vec = to.clone().subtract(from).toVector(); + if (vec.length() <= 70) { + if (middleLine != null) middleLine.hide(true); + return; + } + if (vec.length() > 280) vec.normalize().multiply(280); + else vec = vec.clone().normalize().multiply(vec.length() - 60); + + if (middleLine == null) { + middleLine = new RBlockDisplay(server, new Location(null, 0, 0, 0)); + middleLine.setBrightness(new Display.Brightness(15, 15)); + middleLine.setViewRange(560); + middleLine.setBlock(blockData); + entities.add(middleLine); + } else { + middleLine.hide(false); + } + + Player player = server.getPlayers().stream().findFirst().orElse(null); + if (player == null) return; + + Vector tempVector = vec.clone().normalize().multiply(30); + Location from = this.from.clone().add(tempVector); + Location to = this.to.clone().subtract(tempVector); + + Vector lineVec = to.clone().subtract(from).toVector(); + Vector playerVec = player.getLocation().toVector().subtract(from.toVector()); + double lineVecDotItself = lineVec.dot(lineVec); + Vector projectionVec = lineVec.clone().multiply(lineVec.dot(playerVec)).divide(new Vector(lineVecDotItself, lineVecDotItself, lineVecDotItself)); + + Vector moveVec = from.toVector().add(projectionVec); + if (moveVec.getX() < from.getX()) { + moveVec.setX(from.getX()); + } + if (moveVec.getX() > to.getX()) { + moveVec.setX(to.getX()); + } + if (moveVec.getY() < from.getY()) { + moveVec.setY(from.getY()); + } + if (moveVec.getY() > to.getY()) { + moveVec.setY(to.getY()); + } + if (moveVec.getZ() < from.getZ()) { + moveVec.setZ(from.getZ()); + } + if (moveVec.getZ() > to.getZ()) { + moveVec.setZ(to.getZ()); + } + + Vector translation = vec.clone().divide(new Vector(2, 2, 2)); + translation.setX(-translation.getX()); + translation.setY(-translation.getY()); + translation.setZ(-translation.getZ()); + + Vector first = moveVec.clone().add(translation).subtract(from.toVector()); + if (first.getX() < 0) { + translation.setX(translation.getX() - first.getX()); + } + if (first.getY() < 0) { + translation.setY(translation.getY() - first.getY()); + } + if (first.getZ() < 0) { + translation.setZ(translation.getZ() - first.getZ()); + } + + Vector second = to.toVector().subtract(moveVec.clone().subtract(translation)); + if (second.getX() < 0) { + translation.setX(translation.getX() + second.getX()); + } + if (second.getY() < 0) { + translation.setY(translation.getY() + second.getY()); + } + if (second.getZ() < 0) { + translation.setZ(translation.getZ() + second.getZ()); + } + + middleLine.move(moveVec.toLocation(player.getWorld()).subtract(offsetVec)); + middleLine.setTransform(new Transformation(translation.toVector3f(), new Quaternionf(0, 0, 0, 1), addWidth(vec).toVector3f(), new Quaternionf(0, 0, 0, 1))); + } + + private RBlockDisplay endLine; + private void updateEnd() { + Vector vec = to.clone().subtract(from).toVector(); + if (vec.length() <= 35) { + if (endLine != null) endLine.hide(true); + return; + } + if (vec.length() > 35) vec.normalize().multiply(35); + + if (endLine == null) { + endLine = new RBlockDisplay(server, new Location(null, 0, 0, 0)); + endLine.setBrightness(new Display.Brightness(15, 15)); + endLine.setViewRange(560); + endLine.setBlock(blockData); + entities.add(endLine); + } else { + endLine.hide(false); + } + + endLine.move(to.clone().subtract(offsetVec)); + endLine.setTransform(new Transformation(vec.toVector3f().negate(), new Quaternionf(0, 0, 0, 1), addWidth(vec).toVector3f(), new Quaternionf(0, 0, 0, 1))); + } + + private Vector addWidth(Vector vector) { + vector = vector.clone(); + if (vector.getX() == 0) { + vector.setX(vector.getX() + width); + } + if (vector.getY() == 0) { + vector.setY(vector.getY() + width); + } + if (vector.getZ() == 0) { + vector.setZ(vector.getZ() + width); + } + vector.add(offsetVec).add(offsetVec); + return vector; + } +} From dd5f46069f45c023ea198e8fe3cd08f017a49c12 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Tue, 15 Apr 2025 15:05:06 +0200 Subject: [PATCH 061/153] Delete WorldEditRenderer8 --- .../de/steamwar/core/WorldEditRenderer8.java | 23 ------------------- 1 file changed, 23 deletions(-) delete mode 100644 SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditRenderer8.java diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditRenderer8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditRenderer8.java deleted file mode 100644 index df3a66335..000000000 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditRenderer8.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 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.core; - -public class WorldEditRenderer8 implements WorldEditRenderer { -} From dfc7bbbe1332da6e053614a28093a4c1d48df0a4 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 16 Apr 2025 10:03:30 +0200 Subject: [PATCH 062/153] Fix WorldEditRendererWrapper9 --- .../src/de/steamwar/core/WorldEditRendererWrapper9.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRendererWrapper9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRendererWrapper9.java index 6a06be458..159a89ec3 100644 --- a/SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRendererWrapper9.java +++ b/SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRendererWrapper9.java @@ -70,8 +70,10 @@ public class WorldEditRendererWrapper9 implements WorldEditRendererWrapper { double dx = min.getX() - location.getX(); double dy = min.getY() - location.getY(); double dz = min.getZ() - location.getZ(); - if (dx * dx + dy * dy + dz * dz > SQ_VIEW_DISTANCE) + if (dx * dx + dy * dy + dz * dz > SQ_VIEW_DISTANCE) { + min.add(stepSize); continue; + } player.spawnParticle(particle, min.getX(), min.getY(), min.getZ(), 1, 0.0, 0.0, 0.0, 0.0); min.add(stepSize); From 80a156754d6d947676e5377e7fa3dc4ff59aab41 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 16 Apr 2025 12:54:07 +0200 Subject: [PATCH 063/153] Finalize WorldEditCUI --- .../src/de/steamwar/bausystem/BauSystem.java | 3 + .../de/steamwar/fightsystem/ArenaMode.java | 1 + .../de/steamwar/fightsystem/FightSystem.java | 4 +- .../core/WorldEditRendererWrapper20.java | 20 +-- .../SpigotCore_Main/src/SpigotCore.properties | 19 +++ .../src/SpigotCore_de.properties | 13 +- .../steamwar/WorldEditRendererCUIEditor.java | 157 ++++++++++++++++++ .../de/steamwar/core/WorldEditRenderer.java | 7 +- 8 files changed, 204 insertions(+), 20 deletions(-) create mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/WorldEditRendererCUIEditor.java diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 0d5fa43c3..8256a83df 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem; +import de.steamwar.WorldEditRendererCUIEditor; import de.steamwar.bausystem.config.BauServer; import de.steamwar.bausystem.configplayer.Config; import de.steamwar.bausystem.configplayer.ConfigConverter; @@ -206,6 +207,8 @@ public class BauSystem extends JavaPlugin { TraceManager.instance.init(); TraceRecorder.instance.init(); + + new WorldEditRendererCUIEditor(); } @Override diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ArenaMode.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ArenaMode.java index e96e0204e..eb0a637a3 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ArenaMode.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ArenaMode.java @@ -53,4 +53,5 @@ public enum ArenaMode { public static final Set SoloLeader = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK, PREPARE)); public static final Set NotOnBau = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK, PREPARE, REPLAY))); public static final Set SeriousFight = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK, REPLAY))); + public static final Set CheckOrTest = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK)); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index ce47ee34f..9a99789ca 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -20,6 +20,7 @@ package de.steamwar.fightsystem; import com.comphenix.tinyprotocol.TinyProtocol; +import de.steamwar.WorldEditRendererCUIEditor; import de.steamwar.core.Core; import de.steamwar.fightsystem.commands.*; import de.steamwar.fightsystem.countdown.*; @@ -28,8 +29,8 @@ import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightWorld; import de.steamwar.fightsystem.fight.HotbarKit; -import de.steamwar.fightsystem.listener.Shutdown; import de.steamwar.fightsystem.listener.*; +import de.steamwar.fightsystem.listener.Shutdown; import de.steamwar.fightsystem.record.FileRecorder; import de.steamwar.fightsystem.record.FileSource; import de.steamwar.fightsystem.record.GlobalRecorder; @@ -106,6 +107,7 @@ public class FightSystem extends JavaPlugin { new HotbarKit.HotbarKitListener(); new JoinRequestListener(); new OneShotStateDependent(ArenaMode.All, FightState.PreSchemSetup, () -> Fight.playSound(SWSound.BLOCK_NOTE_PLING.getSound(), 100.0f, 2.0f)); + new OneShotStateDependent(ArenaMode.CheckOrTest, FightState.All, WorldEditRendererCUIEditor::new); new EnterHandler(); techHider = new TechHiderWrapper(); diff --git a/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java b/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java index 5bffe84f5..9e2dd7840 100644 --- a/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java +++ b/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java @@ -19,10 +19,9 @@ package de.steamwar.core; +import de.steamwar.WorldEditRendererCUIEditor; import de.steamwar.entity.CAABox; -import de.steamwar.entity.CAALine; import de.steamwar.entity.REntityServer; -import org.bukkit.Material; import org.bukkit.block.data.BlockData; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -74,21 +73,14 @@ public class WorldEditRendererWrapper20 implements WorldEditRendererWrapper { return entityServer; }); - float width = CAALine.DEFAULT_WIDTH; - if (player != owner) { - width = 1 / 64f; - } - - BlockData block; + WorldEditRendererCUIEditor.Type type; if (player == owner) { - if (clipboard) { - block = Material.LIME_CONCRETE.createBlockData(); - } else { - block = Material.PURPLE_CONCRETE.createBlockData(); - } + type = clipboard ? WorldEditRendererCUIEditor.Type.CLIPBOARD : WorldEditRendererCUIEditor.Type.SELECTION; } else { - block = Material.GRAY_CONCRETE.createBlockData(); + type = clipboard ? WorldEditRendererCUIEditor.Type.CLIPBOARD_OTHER : WorldEditRendererCUIEditor.Type.SELECTION_OTHER; } + float width = type.getWidth(player).value; + BlockData block = type.getMaterial(player).createBlockData(); BoxPair boxPair = boxes.computeIfAbsent(player, __ -> new HashMap<>()).computeIfAbsent(owner, __ -> new BoxPair()); CAABox box = boxPair.get(clipboard); diff --git a/SpigotCore/SpigotCore_Main/src/SpigotCore.properties b/SpigotCore/SpigotCore_Main/src/SpigotCore.properties index 10c64603d..b4cae6871 100644 --- a/SpigotCore/SpigotCore_Main/src/SpigotCore.properties +++ b/SpigotCore/SpigotCore_Main/src/SpigotCore.properties @@ -105,3 +105,22 @@ NOSCHEMSUBMITTING_PERMA=§7You are §epermanently§7 excluded from submitting § NOSCHEMSUBMITTING_UNTIL=§7You are excluded from submitting §e§lschematics §euntil {0}§8: §e{1} UNNOSCHEMSUBMITTING_ERROR=§cThe player is not excluded from submitting schematics. UNNOSCHEMSUBMITTING=§e{0} §7may now submit §e§lschematics§7 again§8. + +WORLDEDIT_CUI_TITLE = WorldEdit CUI +WORLDEDIT_CUI_TITLE_SUBMENU = WorldEdit CUI - {0} +WORLDEDIT_CUI_SELECTION = Selection +WORLDEDIT_CUI_CLIPBOARD = Clipboard +WORLDEDIT_CUI_SELECTION_OTHER = Selection Other +WORLDEDIT_CUI_CLIPBOARD_OTHER = Clipboard Other + +WORLDEDIT_CUI_MATERIAL_NAME = §eWorldEdit {0} +WORLDEDIT_CUI_MATERIAL_CLICK = §7Click to edit + +WORLDEDIT_CUI_WIDTH_NAME = §eWidth {0} +WORLDEDIT_CUI_WIDTH_LORE = §8> §7{0} +WORLDEDIT_CUI_WIDTH_LORE_SELECTED = §8> §e{0} +WORLDEDIT_CUI_WIDTH_CLICK = §7Click to change +WORLDEDIT_CUI_WIDTH_HUGE = 2/16 Block +WORLDEDIT_CUI_WIDTH_LARGE = 1/16 Block +WORLDEDIT_CUI_WIDTH_MEDIUM = 1/32 Block +WORLDEDIT_CUI_WIDTH_SLIM = 1/64 Block \ No newline at end of file diff --git a/SpigotCore/SpigotCore_Main/src/SpigotCore_de.properties b/SpigotCore/SpigotCore_Main/src/SpigotCore_de.properties index 83fa39f52..cc5158eae 100644 --- a/SpigotCore/SpigotCore_Main/src/SpigotCore_de.properties +++ b/SpigotCore/SpigotCore_Main/src/SpigotCore_de.properties @@ -99,4 +99,15 @@ NOSCHEMSUBMITTING_TEAM={0} §e{1} §7wurde von §e{2} {3} §7vom §e§lSchematic NOSCHEMSUBMITTING_PERMA=§7Du bist §epermanent §7vom §e§lEinsenden von Schematics§7 ausgeschlossen§8: §e{0} NOSCHEMSUBMITTING_UNTIL=§7Du bist §ebis zum {0} §7vom §e§lEinsenden von Schematics§7 ausgeschlossen§8: §e{1} UNNOSCHEMSUBMITTING_ERROR=§cDer Spieler ist nicht vom Einsenden von Schematics ausgeschlossen. -UNNOSCHEMSUBMITTING=§e{0} §7darf nun wieder §e§lSchematis§7 einsenden§8. \ No newline at end of file +UNNOSCHEMSUBMITTING=§e{0} §7darf nun wieder §e§lSchematis§7 einsenden§8. + +WORLDEDIT_CUI_SELECTION = Auswahl +WORLDEDIT_CUI_CLIPBOARD = Kopie +WORLDEDIT_CUI_SELECTION_OTHER = Auswahl Anderer +WORLDEDIT_CUI_CLIPBOARD_OTHER = Kopie Anderer + +WORLDEDIT_CUI_MATERIAL_NAME = §eWorldEdit {0} +WORLDEDIT_CUI_MATERIAL_CLICK = §7Klicke zum Editieren + +WORLDEDIT_CUI_WIDTH_NAME = §eDicke - {0} +WORLDEDIT_CUI_WIDTH_CLICK = §7Klicke zum ändern \ No newline at end of file diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/WorldEditRendererCUIEditor.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/WorldEditRendererCUIEditor.java new file mode 100644 index 000000000..6bd0f60a9 --- /dev/null +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/WorldEditRendererCUIEditor.java @@ -0,0 +1,157 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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; + +import de.steamwar.command.SWCommand; +import de.steamwar.core.Core; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import de.steamwar.sql.UserConfig; +import lombok.AllArgsConstructor; +import org.bukkit.Material; +import org.bukkit.block.data.type.Light; +import org.bukkit.entity.Player; +import org.bukkit.inventory.meta.BlockDataMeta; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class WorldEditRendererCUIEditor { + + @AllArgsConstructor + public enum Type { + SELECTION("cui_selection_material", "cui_selection_width", Material.PURPLE_CONCRETE, Width.LARGE), + CLIPBOARD("cui_clipboard_material", "cui_clipboard_width", Material.LIME_CONCRETE, Width.LARGE), + SELECTION_OTHER("cui_selection_other_material", "cui_selection_other_width", Material.GRAY_CONCRETE, Width.SLIM), + CLIPBOARD_OTHER("cui_clipboard_other_material", "cui_clipboard_other_width", Material.GRAY_CONCRETE, Width.SLIM); + + private final String configMaterial; + private final String configWidth; + private final Material defaultMaterial; + private final Width defaultWidth; + + public Material getMaterial(Player player) { + String material = UserConfig.getConfig(player.getUniqueId(), configMaterial); + if (material == null) { + return defaultMaterial; + } else { + return Material.valueOf(material); + } + } + + public void setMaterial(Player player, Material material) { + UserConfig.updatePlayerConfig(player.getUniqueId(), configMaterial, material.name()); + } + + public Width getWidth(Player player) { + String width = UserConfig.getConfig(player.getUniqueId(), configWidth); + if (width == null) { + return defaultWidth; + } else { + return Width.valueOf(width); + } + } + + public void setWidth(Player player, Width width) { + UserConfig.updatePlayerConfig(player.getUniqueId(), configWidth, width.name()); + } + } + + @AllArgsConstructor + public enum Width { + HUGE(15, "WORLDEDIT_CUI_WIDTH_HUGE", 2/16f), + LARGE(8, "WORLDEDIT_CUI_WIDTH_LARGE", 1/16f), + MEDIUM(4, "WORLDEDIT_CUI_WIDTH_MEDIUM", 1/32f), + SLIM(0, "WORLDEDIT_CUI_WIDTH_SLIM", 1/64f); + + public final int lightLevel; + public final String name; + public final float value; + } + + public WorldEditRendererCUIEditor() { + new Command(); + } + + private static class Command extends SWCommand { + + public Command() { + super("cui"); + } + + @Register + public void cuiEditor(Player player) { + SWInventory inv = new SWInventory(player, 9 * 2, Core.MESSAGE.parse("WORLDEDIT_CUI_TITLE", player)); + setElement(inv, player, 1, "WORLDEDIT_CUI_SELECTION", Type.SELECTION); + setElement(inv, player, 3, "WORLDEDIT_CUI_CLIPBOARD", Type.CLIPBOARD); + setElement(inv, player, 5, "WORLDEDIT_CUI_SELECTION_OTHER", Type.SELECTION_OTHER); + setElement(inv, player, 7, "WORLDEDIT_CUI_CLIPBOARD_OTHER", Type.CLIPBOARD_OTHER); + inv.open(); + } + + private void setElement(SWInventory inv, Player player, int index, String uiName, Type type) { + Material material = type.getMaterial(player); + Width width = type.getWidth(player); + + inv.setItem(index, new SWItem(material, Core.MESSAGE.parse("WORLDEDIT_CUI_MATERIAL_NAME", player, Core.MESSAGE.parse(uiName, player)), Arrays.asList(Core.MESSAGE.parse("WORLDEDIT_CUI_MATERIAL_CLICK", player)), false, click -> { + cuiMaterial(player, uiName, type, material); + })); + + List lore = new ArrayList<>(); + lore.add(Core.MESSAGE.parse("WORLDEDIT_CUI_WIDTH_CLICK", player)); + lore.add(""); + for (Width value : Width.values()) { + if (value == width) { + lore.add(Core.MESSAGE.parse("WORLDEDIT_CUI_WIDTH_LORE_SELECTED", player, Core.MESSAGE.parse(value.name, player))); + } else { + lore.add(Core.MESSAGE.parse("WORLDEDIT_CUI_WIDTH_LORE", player, Core.MESSAGE.parse(value.name, player))); + } + } + SWItem lightItem = new SWItem(Material.LIGHT, Core.MESSAGE.parse("WORLDEDIT_CUI_WIDTH_NAME", player, Core.MESSAGE.parse(uiName, player)), lore, false, click -> { + type.setWidth(player, Width.values()[(width.ordinal() + 1) % Width.values().length]); + setElement(inv, player, index, uiName, type); + }); + ItemMeta itemMeta = lightItem.getItemMeta(); + Light light = (Light) Material.LIGHT.createBlockData(); + light.setLevel(width.lightLevel); + ((BlockDataMeta) itemMeta).setBlockData(light); + lightItem.setItemMeta(itemMeta); + inv.setItem(index + 9, lightItem); + } + + private final Material[] materials = {Material.WHITE_CONCRETE, Material.LIGHT_GRAY_CONCRETE, Material.GRAY_CONCRETE, Material.BLACK_CONCRETE, Material.BROWN_CONCRETE, Material.RED_CONCRETE, Material.ORANGE_CONCRETE, Material.YELLOW_CONCRETE, Material.LIME_CONCRETE, Material.GREEN_CONCRETE, Material.CYAN_CONCRETE, Material.LIGHT_BLUE_CONCRETE, Material.BLUE_CONCRETE, Material.PURPLE_CONCRETE, Material.MAGENTA_CONCRETE, Material.PINK_CONCRETE, null, Material.BARRIER}; + + private void cuiMaterial(Player player, String subMenu, Type type, Material currentSelection) { + SWInventory inv = new SWInventory(player, 9 * 2, Core.MESSAGE.parse("WORLDEDIT_CUI_TITLE_SUBMENU", player, Core.MESSAGE.parse(subMenu, player))); + for (int i = 0; i < materials.length; i++) { + Material material = materials[i]; + if (material == null) continue; + inv.setItem(i, new SWItem(material, "", Collections.emptyList(), material == currentSelection, click -> { + type.setMaterial(player, material); + cuiEditor(player); + })); + } + inv.open(); + } + } +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java index 7bf68c99b..faed64e37 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java @@ -72,7 +72,6 @@ public class WorldEditRenderer implements Listener { Vector b = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMaximum(region).subtract(WorldEditWrapper.impl.getOrigin(clipboard)), transform).add(pos); a = new Vector(a.getBlockX(), a.getBlockY(), a.getBlockZ()); b = new Vector(b.getBlockX(), b.getBlockY(), b.getBlockZ()); - WorldEditRendererWrapper.impl.hide(player, player, true, false); drawCuboid(Vector.getMinimum(a, b), Vector.getMaximum(a, b), true, player); } catch (EmptyClipboardException e) { WorldEditRendererWrapper.impl.hide(player, player, true, true); @@ -85,7 +84,6 @@ public class WorldEditRenderer implements Listener { RegionSelector regionSelector = session.getRegionSelector(world); try { Region region = regionSelector.getRegion(); - WorldEditRendererWrapper.impl.hide(player, player, false, false); drawCuboid(WorldEditWrapper.impl.getMinimum(region), WorldEditWrapper.impl.getMaximum(region), false, player); } catch (IncompleteRegionException e) { WorldEditRendererWrapper.impl.hide(player, player, false, true); @@ -114,8 +112,9 @@ public class WorldEditRenderer implements Listener { @EventHandler public void onPlayerMove(PlayerMoveEvent event) { - WorldEditRendererWrapper.impl.tick(event.getPlayer()); - + if(event.getPlayer().getItemInHand().getType() == WAND) { + WorldEditRendererWrapper.impl.tick(event.getPlayer()); + } renderClipboard(event.getPlayer(), we.getSession(event.getPlayer())); } From 40437afb7321451e375ecbf138a624dae6cb9c9f Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 16 Apr 2025 13:57:01 +0200 Subject: [PATCH 064/153] Final fixes --- .../src/de/steamwar/bausystem/BauSystem.java | 2 +- .../src/de/steamwar/fightsystem/FightSystem.java | 2 +- .../de/steamwar/core/WorldEditRendererWrapper20.java | 8 ++++++-- SpigotCore/SpigotCore_Main/src/SpigotCore.properties | 10 +++++----- .../SpigotCore_Main/src/SpigotCore_de.properties | 4 ++-- .../src/de/steamwar/core/WorldEditRenderer.java | 8 ++++++-- .../{ => core}/WorldEditRendererCUIEditor.java | 7 ++++--- 7 files changed, 25 insertions(+), 16 deletions(-) rename SpigotCore/SpigotCore_Main/src/de/steamwar/{ => core}/WorldEditRendererCUIEditor.java (98%) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 8256a83df..8376f0f19 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem; -import de.steamwar.WorldEditRendererCUIEditor; +import de.steamwar.core.WorldEditRendererCUIEditor; import de.steamwar.bausystem.config.BauServer; import de.steamwar.bausystem.configplayer.Config; import de.steamwar.bausystem.configplayer.ConfigConverter; diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 9a99789ca..949d7691f 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -20,7 +20,7 @@ package de.steamwar.fightsystem; import com.comphenix.tinyprotocol.TinyProtocol; -import de.steamwar.WorldEditRendererCUIEditor; +import de.steamwar.core.WorldEditRendererCUIEditor; import de.steamwar.core.Core; import de.steamwar.fightsystem.commands.*; import de.steamwar.fightsystem.countdown.*; diff --git a/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java b/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java index 9e2dd7840..fd6e20eba 100644 --- a/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java +++ b/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java @@ -19,9 +19,9 @@ package de.steamwar.core; -import de.steamwar.WorldEditRendererCUIEditor; import de.steamwar.entity.CAABox; import de.steamwar.entity.REntityServer; +import org.bukkit.Material; import org.bukkit.block.data.BlockData; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -80,7 +80,11 @@ public class WorldEditRendererWrapper20 implements WorldEditRendererWrapper { type = clipboard ? WorldEditRendererCUIEditor.Type.CLIPBOARD_OTHER : WorldEditRendererCUIEditor.Type.SELECTION_OTHER; } float width = type.getWidth(player).value; - BlockData block = type.getMaterial(player).createBlockData(); + Material material = type.getMaterial(player); + if (material == Material.BARRIER) { + hide(player, null, clipboard, true); + } + BlockData block = material.createBlockData(); BoxPair boxPair = boxes.computeIfAbsent(player, __ -> new HashMap<>()).computeIfAbsent(owner, __ -> new BoxPair()); CAABox box = boxPair.get(clipboard); diff --git a/SpigotCore/SpigotCore_Main/src/SpigotCore.properties b/SpigotCore/SpigotCore_Main/src/SpigotCore.properties index b4cae6871..94e57d6ca 100644 --- a/SpigotCore/SpigotCore_Main/src/SpigotCore.properties +++ b/SpigotCore/SpigotCore_Main/src/SpigotCore.properties @@ -108,10 +108,10 @@ UNNOSCHEMSUBMITTING=§e{0} §7may now submit §e§lschematics§7 again§8. WORLDEDIT_CUI_TITLE = WorldEdit CUI WORLDEDIT_CUI_TITLE_SUBMENU = WorldEdit CUI - {0} -WORLDEDIT_CUI_SELECTION = Selection -WORLDEDIT_CUI_CLIPBOARD = Clipboard -WORLDEDIT_CUI_SELECTION_OTHER = Selection Other -WORLDEDIT_CUI_CLIPBOARD_OTHER = Clipboard Other +WORLDEDIT_CUI_SELECTION = Own Selection +WORLDEDIT_CUI_CLIPBOARD = Own Clipboard +WORLDEDIT_CUI_SELECTION_OTHER = Other Selection +WORLDEDIT_CUI_CLIPBOARD_OTHER = Other Clipboard WORLDEDIT_CUI_MATERIAL_NAME = §eWorldEdit {0} WORLDEDIT_CUI_MATERIAL_CLICK = §7Click to edit @@ -120,7 +120,7 @@ WORLDEDIT_CUI_WIDTH_NAME = §eWidth {0} WORLDEDIT_CUI_WIDTH_LORE = §8> §7{0} WORLDEDIT_CUI_WIDTH_LORE_SELECTED = §8> §e{0} WORLDEDIT_CUI_WIDTH_CLICK = §7Click to change -WORLDEDIT_CUI_WIDTH_HUGE = 2/16 Block +WORLDEDIT_CUI_WIDTH_HUGE = 1/ 8 Block WORLDEDIT_CUI_WIDTH_LARGE = 1/16 Block WORLDEDIT_CUI_WIDTH_MEDIUM = 1/32 Block WORLDEDIT_CUI_WIDTH_SLIM = 1/64 Block \ No newline at end of file diff --git a/SpigotCore/SpigotCore_Main/src/SpigotCore_de.properties b/SpigotCore/SpigotCore_Main/src/SpigotCore_de.properties index cc5158eae..1f573eff4 100644 --- a/SpigotCore/SpigotCore_Main/src/SpigotCore_de.properties +++ b/SpigotCore/SpigotCore_Main/src/SpigotCore_de.properties @@ -101,8 +101,8 @@ NOSCHEMSUBMITTING_UNTIL=§7Du bist §ebis zum {0} §7vom §e§lEinsenden von Sch UNNOSCHEMSUBMITTING_ERROR=§cDer Spieler ist nicht vom Einsenden von Schematics ausgeschlossen. UNNOSCHEMSUBMITTING=§e{0} §7darf nun wieder §e§lSchematis§7 einsenden§8. -WORLDEDIT_CUI_SELECTION = Auswahl -WORLDEDIT_CUI_CLIPBOARD = Kopie +WORLDEDIT_CUI_SELECTION = Eigene Auswahl +WORLDEDIT_CUI_CLIPBOARD = Eigene Kopie WORLDEDIT_CUI_SELECTION_OTHER = Auswahl Anderer WORLDEDIT_CUI_CLIPBOARD_OTHER = Kopie Anderer diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java index faed64e37..6d84963ca 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java @@ -120,12 +120,16 @@ public class WorldEditRenderer implements Listener { @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { - renderRegion(event.getPlayer(), we.getSession(event.getPlayer())); + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { + renderRegion(event.getPlayer(), we.getSession(event.getPlayer())); + }, 0); } @EventHandler public void onBlockBreak(BlockBreakEvent event) { - renderRegion(event.getPlayer(), we.getSession(event.getPlayer())); + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { + renderRegion(event.getPlayer(), we.getSession(event.getPlayer())); + }, 0); } @EventHandler diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/WorldEditRendererCUIEditor.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererCUIEditor.java similarity index 98% rename from SpigotCore/SpigotCore_Main/src/de/steamwar/WorldEditRendererCUIEditor.java rename to SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererCUIEditor.java index 6bd0f60a9..ed048de88 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/WorldEditRendererCUIEditor.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererCUIEditor.java @@ -17,10 +17,9 @@ * along with this program. If not, see . */ -package de.steamwar; +package de.steamwar.core; import de.steamwar.command.SWCommand; -import de.steamwar.core.Core; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.sql.UserConfig; @@ -90,7 +89,9 @@ public class WorldEditRendererCUIEditor { } public WorldEditRendererCUIEditor() { - new Command(); + if (Core.getVersion() >= 21) { + new Command(); + } } private static class Command extends SWCommand { From f6852a55232f85ca1833b11aef8cf27c677f8dd3 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 16 Apr 2025 18:57:03 +0200 Subject: [PATCH 065/153] Add WorldEditRendererCUIEditor to Builder server --- Teamserver/src/de/steamwar/teamserver/Builder.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Teamserver/src/de/steamwar/teamserver/Builder.java b/Teamserver/src/de/steamwar/teamserver/Builder.java index 137906ada..55aeed2d1 100644 --- a/Teamserver/src/de/steamwar/teamserver/Builder.java +++ b/Teamserver/src/de/steamwar/teamserver/Builder.java @@ -19,6 +19,7 @@ package de.steamwar.teamserver; +import de.steamwar.core.WorldEditRendererCUIEditor; import de.steamwar.message.Message; import de.steamwar.teamserver.command.*; import de.steamwar.teamserver.listener.AxiomHandshakeListener; @@ -58,6 +59,7 @@ public final class Builder extends JavaPlugin { Bukkit.getPluginManager().registerEvents(materialCommand, this); Bukkit.getWorlds().get(0).setGameRule(GameRule.REDUCED_DEBUG_INFO, false); + new WorldEditRendererCUIEditor(); } @Override From d975110470907c1b0b792d56a03b73eaa00bcc0b Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 16 Apr 2025 19:03:01 +0200 Subject: [PATCH 066/153] Final fixes --- .../src/de/steamwar/core/WorldEditRendererWrapper20.java | 3 ++- .../src/de/steamwar/core/WorldEditRendererCUIEditor.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java b/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java index fd6e20eba..55dd9e480 100644 --- a/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java +++ b/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java @@ -82,7 +82,8 @@ public class WorldEditRendererWrapper20 implements WorldEditRendererWrapper { float width = type.getWidth(player).value; Material material = type.getMaterial(player); if (material == Material.BARRIER) { - hide(player, null, clipboard, true); + hide(player, owner, clipboard, true); + return; } BlockData block = material.createBlockData(); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererCUIEditor.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererCUIEditor.java index ed048de88..46fe53ded 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererCUIEditor.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererCUIEditor.java @@ -89,7 +89,7 @@ public class WorldEditRendererCUIEditor { } public WorldEditRendererCUIEditor() { - if (Core.getVersion() >= 21) { + if (Core.getVersion() >= 20) { new Command(); } } From 3e448e7597a810872df40ef30ca794e08cb7cd05 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 16 Apr 2025 20:11:55 +0200 Subject: [PATCH 067/153] Remove default methods of WorldEditRendererWrapper --- .../steamwar/core/WorldEditRendererWrapper8.java | 12 ++++++++++++ .../steamwar/core/WorldEditRendererWrapper9.java | 14 +++++++++++++- .../de/steamwar/core/WorldEditRendererWrapper.java | 9 +++------ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditRendererWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditRendererWrapper8.java index 1ca68b2d7..3a9042ed7 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditRendererWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditRendererWrapper8.java @@ -27,4 +27,16 @@ public class WorldEditRendererWrapper8 implements WorldEditRendererWrapper { @Override public void draw(Player player, Player owner, boolean clipboard, Vector pos1, Vector pos2) { } + + @Override + public void tick(Player player) { + } + + @Override + public void hide(Player player, Player owner, boolean clipboard, boolean hide) { + } + + @Override + public void remove(Player player) { + } } diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRendererWrapper9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRendererWrapper9.java index 159a89ec3..579b5f148 100644 --- a/SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRendererWrapper9.java +++ b/SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRendererWrapper9.java @@ -52,7 +52,7 @@ public class WorldEditRendererWrapper9 implements WorldEditRendererWrapper { drawLine(player, owner, clipboard, new Vector(max.getX(), max.getY(), min.getZ()), new Vector(max.getX(), max.getY(), max.getZ())); } - public void drawLine(Player player, Player owner, boolean clipboard, Vector min, Vector max) { + private void drawLine(Player player, Player owner, boolean clipboard, Vector min, Vector max) { Particle particle; if (player == owner) { if (clipboard) { @@ -79,4 +79,16 @@ public class WorldEditRendererWrapper9 implements WorldEditRendererWrapper { min.add(stepSize); } } + + @Override + public void tick(Player player) { + } + + @Override + public void hide(Player player, Player owner, boolean clipboard, boolean hide) { + } + + @Override + public void remove(Player player) { + } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererWrapper.java index 63380fdcd..fd6c0ea1c 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererWrapper.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererWrapper.java @@ -36,12 +36,9 @@ public interface WorldEditRendererWrapper { void draw(Player player, Player owner, boolean clipboard, Vector pos1, Vector pos2); - default void tick(Player player) { - } + void tick(Player player); - default void hide(Player player, Player owner, boolean clipboard, boolean hide) { - } + void hide(Player player, Player owner, boolean clipboard, boolean hide); - default void remove(Player player) { - } + void remove(Player player); } From cc4532ab90254ec17949e73ef5282f99190b0e2d Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 12 Jun 2025 18:50:13 +0200 Subject: [PATCH 068/153] Update CAALine to CLine Update CAABox to CWireframe --- .../core/WorldEditRendererWrapper20.java | 18 +- .../src/de/steamwar/entity/CAABox.java | 103 -------- .../src/de/steamwar/entity/CAALine.java | 246 ------------------ 3 files changed, 9 insertions(+), 358 deletions(-) delete mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CAABox.java delete mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CAALine.java diff --git a/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java b/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java index 55dd9e480..58d8c4e93 100644 --- a/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java +++ b/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import de.steamwar.entity.CAABox; +import de.steamwar.entity.CWireframe; import de.steamwar.entity.REntityServer; import org.bukkit.Material; import org.bukkit.block.data.BlockData; @@ -33,10 +33,10 @@ import java.util.Map; public class WorldEditRendererWrapper20 implements WorldEditRendererWrapper { private static final class BoxPair { - private CAABox regionBox; - private CAABox clipboardBox; + private CWireframe regionBox; + private CWireframe clipboardBox; - public CAABox get(boolean clipboard) { + public CWireframe get(boolean clipboard) { if (clipboard) { return clipboardBox; } else { @@ -44,7 +44,7 @@ public class WorldEditRendererWrapper20 implements WorldEditRendererWrapper { } } - public void set(boolean clipboard, CAABox box) { + public void set(boolean clipboard, CWireframe box) { if (clipboard) { this.clipboardBox = box; } else { @@ -88,9 +88,9 @@ public class WorldEditRendererWrapper20 implements WorldEditRendererWrapper { BlockData block = material.createBlockData(); BoxPair boxPair = boxes.computeIfAbsent(player, __ -> new HashMap<>()).computeIfAbsent(owner, __ -> new BoxPair()); - CAABox box = boxPair.get(clipboard); + CWireframe box = boxPair.get(clipboard); if (box == null) { - box = new CAABox(server); + box = new CWireframe(server); boxPair.set(clipboard, box); } box.setPos1(null).setPos2(null); @@ -112,11 +112,11 @@ public class WorldEditRendererWrapper20 implements WorldEditRendererWrapper { if (owner != null) { BoxPair boxPair = pairs.get(owner); if (boxPair == null) return; - CAABox box = boxPair.get(clipboard); + CWireframe box = boxPair.get(clipboard); if (box != null) box.hide(hide); } else { pairs.values().forEach(boxPair -> { - CAABox box = boxPair.get(clipboard); + CWireframe box = boxPair.get(clipboard); if (box != null) box.hide(hide); }); } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CAABox.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CAABox.java deleted file mode 100644 index 80d94c88f..000000000 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CAABox.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 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.entity; - -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.block.data.BlockData; -import org.bukkit.util.Vector; - -import java.util.List; - -/** - * Compound Axis Aligned Box (12 CAALine) - */ -public class CAABox extends CEntity { - - public static final float DEFAULT_WIDTH = 1 / 16f; - private float width = DEFAULT_WIDTH; - - private Location pos1; - private Location pos2; - - public CAABox(REntityServer server) { - super(server); - } - - public CAABox setPos1(Location pos1) { - this.pos1 = pos1; - updateAndSpawnLines(); - return this; - } - - public CAABox setPos2(Location pos2) { - this.pos2 = pos2; - updateAndSpawnLines(); - return this; - } - - public CAABox setWidth(float width) { - this.width = width; - updateAndSpawnLines(); - getEntitiesByType(CAALine.class).forEach(haaLine -> { - haaLine.setWidth(width); - }); - return this; - } - - public CAABox setBlock(BlockData blockData) { - getEntitiesByType(CAALine.class).forEach(haaLine -> { - haaLine.setBlock(blockData); - }); - return this; - } - - private void updateAndSpawnLines() { - if (pos1 == null || pos2 == null) return; - if (entities.isEmpty()) { - for (int i = 0; i < 12; i++) { - entities.add(new CAALine(server)); - } - } - - World world = pos1.getWorld(); - Vector min = Vector.getMinimum(pos1.toVector(), pos2.toVector()); - Vector max = Vector.getMaximum(pos1.toVector(), pos2.toVector()) - .add(new Vector(1 - width, 1 - width, 1 - width)); - - List lines = getEntitiesByType(CAALine.class); - lines.forEach(line -> line.setFrom(null).setTo(null)); - - lines.get(0).setFrom(new Vector(min.getX(), min.getY(), min.getZ()).toLocation(world)).setTo(new Vector(max.getX() + width, min.getY(), min.getZ()).toLocation(world)); - lines.get(1).setFrom(new Vector(min.getX(), max.getY(), min.getZ()).toLocation(world)).setTo(new Vector(max.getX() + width, max.getY(), min.getZ()).toLocation(world)); - lines.get(2).setFrom(new Vector(min.getX(), min.getY(), max.getZ()).toLocation(world)).setTo(new Vector(max.getX() + width, min.getY(), max.getZ()).toLocation(world)); - lines.get(3).setFrom(new Vector(min.getX(), max.getY(), max.getZ()).toLocation(world)).setTo(new Vector(max.getX() + width, max.getY(), max.getZ()).toLocation(world)); - - lines.get(4).setFrom(new Vector(min.getX(), min.getY(), min.getZ()).toLocation(world)).setTo(new Vector(min.getX(), max.getY() + width, min.getZ()).toLocation(world)); - lines.get(5).setFrom(new Vector(max.getX(), min.getY(), min.getZ()).toLocation(world)).setTo(new Vector(max.getX(), max.getY() + width, min.getZ()).toLocation(world)); - lines.get(6).setFrom(new Vector(min.getX(), min.getY(), max.getZ()).toLocation(world)).setTo(new Vector(min.getX(), max.getY() + width, max.getZ()).toLocation(world)); - lines.get(7).setFrom(new Vector(max.getX(), min.getY(), max.getZ()).toLocation(world)).setTo(new Vector(max.getX(), max.getY() + width, max.getZ()).toLocation(world)); - - lines.get(8).setFrom(new Vector(min.getX(), min.getY(), min.getZ()).toLocation(world)).setTo(new Vector(min.getX(), min.getY(), max.getZ() + width).toLocation(world)); - lines.get(9).setFrom(new Vector(max.getX(), min.getY(), min.getZ()).toLocation(world)).setTo(new Vector(max.getX(), min.getY(), max.getZ() + width).toLocation(world)); - lines.get(10).setFrom(new Vector(min.getX(), max.getY(), min.getZ()).toLocation(world)).setTo(new Vector(min.getX(), max.getY(), max.getZ() + width).toLocation(world)); - lines.get(11).setFrom(new Vector(max.getX(), max.getY(), min.getZ()).toLocation(world)).setTo(new Vector(max.getX(), max.getY(), max.getZ() + width).toLocation(world)); - } -} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CAALine.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CAALine.java deleted file mode 100644 index 19a6ef9f8..000000000 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/CAALine.java +++ /dev/null @@ -1,246 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 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.entity; - -import org.bukkit.Location; -import org.bukkit.block.data.BlockData; -import org.bukkit.entity.Display; -import org.bukkit.entity.Player; -import org.bukkit.util.Transformation; -import org.bukkit.util.Vector; -import org.joml.Quaternionf; -import org.joml.Vector3f; - -import java.util.Objects; - -public class CAALine extends CEntity { - - public static final float DEFAULT_WIDTH = 1 / 16f; - private static final float offset = 1 / 1024f; - private static final Vector offsetVec = new Vector(offset, offset, offset); - - private Location from; - private Location to; - private float width = DEFAULT_WIDTH; - private BlockData blockData = RBlockDisplay.DEFAULT_BLOCK; - - public CAALine(REntityServer server) { - super(server); - tick(); - } - - public CAALine setFrom(Location from) { - if (Objects.equals(from, this.from)) return this; - this.from = from; - tick(); - return this; - } - - public CAALine setTo(Location to) { - if (Objects.equals(to, this.to)) return this; - this.to = to; - tick(); - return this; - } - - public CAALine setWidth(float width) { - if (this.width == width) return this; - this.width = width; - tick(); - return this; - } - - public CAALine setBlock(BlockData blockData) { - if (this.blockData.equals(blockData)) return this; - if (blockData == null) { - this.blockData = RBlockDisplay.DEFAULT_BLOCK; - } else { - this.blockData = blockData; - } - getEntitiesByType(RBlockDisplay.class).forEach(display -> { - display.setBlock(blockData); - }); - return this; - } - - private boolean hide = false; - - @Override - public void hide(boolean hide) { - if (hide == this.hide) return; - this.hide = hide; - if (hide) { - if (startLine != null) startLine.hide(true); - if (middleLine != null) middleLine.hide(true); - if (endLine != null) endLine.hide(true); - } else { - tick(); - } - } - - @Override - void tick() { - if (from == null || to == null) return; - if (hide) return; - updateStart(); - updateMiddle(); - updateEnd(); - } - - private RBlockDisplay startLine; - private void updateStart() { - Vector vec = to.clone().subtract(from).toVector(); - if (vec.length() > 35) vec.normalize().multiply(35); - - if (startLine == null) { - startLine = new RBlockDisplay(server, new Location(null, 0, 0, 0)); - startLine.setBrightness(new Display.Brightness(15, 15)); - startLine.setViewRange(560); - startLine.setBlock(blockData); - entities.add(startLine); - } else { - startLine.hide(false); - } - - startLine.move(from.clone().subtract(offsetVec)); - startLine.setTransform(new Transformation(new Vector3f(0, 0, 0), new Quaternionf(0, 0, 0, 1), addWidth(vec).toVector3f(), new Quaternionf(0, 0, 0, 1))); - } - - private RBlockDisplay middleLine; - private void updateMiddle() { - Vector vec = to.clone().subtract(from).toVector(); - if (vec.length() <= 70) { - if (middleLine != null) middleLine.hide(true); - return; - } - if (vec.length() > 280) vec.normalize().multiply(280); - else vec = vec.clone().normalize().multiply(vec.length() - 60); - - if (middleLine == null) { - middleLine = new RBlockDisplay(server, new Location(null, 0, 0, 0)); - middleLine.setBrightness(new Display.Brightness(15, 15)); - middleLine.setViewRange(560); - middleLine.setBlock(blockData); - entities.add(middleLine); - } else { - middleLine.hide(false); - } - - Player player = server.getPlayers().stream().findFirst().orElse(null); - if (player == null) return; - - Vector tempVector = vec.clone().normalize().multiply(30); - Location from = this.from.clone().add(tempVector); - Location to = this.to.clone().subtract(tempVector); - - Vector lineVec = to.clone().subtract(from).toVector(); - Vector playerVec = player.getLocation().toVector().subtract(from.toVector()); - double lineVecDotItself = lineVec.dot(lineVec); - Vector projectionVec = lineVec.clone().multiply(lineVec.dot(playerVec)).divide(new Vector(lineVecDotItself, lineVecDotItself, lineVecDotItself)); - - Vector moveVec = from.toVector().add(projectionVec); - if (moveVec.getX() < from.getX()) { - moveVec.setX(from.getX()); - } - if (moveVec.getX() > to.getX()) { - moveVec.setX(to.getX()); - } - if (moveVec.getY() < from.getY()) { - moveVec.setY(from.getY()); - } - if (moveVec.getY() > to.getY()) { - moveVec.setY(to.getY()); - } - if (moveVec.getZ() < from.getZ()) { - moveVec.setZ(from.getZ()); - } - if (moveVec.getZ() > to.getZ()) { - moveVec.setZ(to.getZ()); - } - - Vector translation = vec.clone().divide(new Vector(2, 2, 2)); - translation.setX(-translation.getX()); - translation.setY(-translation.getY()); - translation.setZ(-translation.getZ()); - - Vector first = moveVec.clone().add(translation).subtract(from.toVector()); - if (first.getX() < 0) { - translation.setX(translation.getX() - first.getX()); - } - if (first.getY() < 0) { - translation.setY(translation.getY() - first.getY()); - } - if (first.getZ() < 0) { - translation.setZ(translation.getZ() - first.getZ()); - } - - Vector second = to.toVector().subtract(moveVec.clone().subtract(translation)); - if (second.getX() < 0) { - translation.setX(translation.getX() + second.getX()); - } - if (second.getY() < 0) { - translation.setY(translation.getY() + second.getY()); - } - if (second.getZ() < 0) { - translation.setZ(translation.getZ() + second.getZ()); - } - - middleLine.move(moveVec.toLocation(player.getWorld()).subtract(offsetVec)); - middleLine.setTransform(new Transformation(translation.toVector3f(), new Quaternionf(0, 0, 0, 1), addWidth(vec).toVector3f(), new Quaternionf(0, 0, 0, 1))); - } - - private RBlockDisplay endLine; - private void updateEnd() { - Vector vec = to.clone().subtract(from).toVector(); - if (vec.length() <= 35) { - if (endLine != null) endLine.hide(true); - return; - } - if (vec.length() > 35) vec.normalize().multiply(35); - - if (endLine == null) { - endLine = new RBlockDisplay(server, new Location(null, 0, 0, 0)); - endLine.setBrightness(new Display.Brightness(15, 15)); - endLine.setViewRange(560); - endLine.setBlock(blockData); - entities.add(endLine); - } else { - endLine.hide(false); - } - - endLine.move(to.clone().subtract(offsetVec)); - endLine.setTransform(new Transformation(vec.toVector3f().negate(), new Quaternionf(0, 0, 0, 1), addWidth(vec).toVector3f(), new Quaternionf(0, 0, 0, 1))); - } - - private Vector addWidth(Vector vector) { - vector = vector.clone(); - if (vector.getX() == 0) { - vector.setX(vector.getX() + width); - } - if (vector.getY() == 0) { - vector.setY(vector.getY() + width); - } - if (vector.getZ() == 0) { - vector.setZ(vector.getZ() + width); - } - vector.add(offsetVec).add(offsetVec); - return vector; - } -} From 4383e541d8bbb50f7c4b578ee79a63da4ffaca7d Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 26 Jun 2025 20:46:01 +0200 Subject: [PATCH 069/153] Fix some stuff --- .../de/steamwar/fightsystem/ArenaMode.java | 1 - .../de/steamwar/fightsystem/FightSystem.java | 2 +- .../src/de/steamwar/core/Core.java | 37 +---------- .../src/de/steamwar/core/PlayerVersion.java | 65 +++++++++++++++++++ .../de/steamwar/core/WorldEditRenderer.java | 5 -- .../core/WorldEditRendererWrapper.java | 2 +- 6 files changed, 69 insertions(+), 43 deletions(-) create mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/core/PlayerVersion.java diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ArenaMode.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ArenaMode.java index eb0a637a3..e96e0204e 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ArenaMode.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ArenaMode.java @@ -53,5 +53,4 @@ public enum ArenaMode { public static final Set SoloLeader = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK, PREPARE)); public static final Set NotOnBau = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK, PREPARE, REPLAY))); public static final Set SeriousFight = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK, REPLAY))); - public static final Set CheckOrTest = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK)); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 949d7691f..9ebc4f0c9 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -107,7 +107,7 @@ public class FightSystem extends JavaPlugin { new HotbarKit.HotbarKitListener(); new JoinRequestListener(); new OneShotStateDependent(ArenaMode.All, FightState.PreSchemSetup, () -> Fight.playSound(SWSound.BLOCK_NOTE_PLING.getSound(), 100.0f, 2.0f)); - new OneShotStateDependent(ArenaMode.CheckOrTest, FightState.All, WorldEditRendererCUIEditor::new); + new OneShotStateDependent(ArenaMode.Test, FightState.All, WorldEditRendererCUIEditor::new); new EnterHandler(); techHider = new TechHiderWrapper(); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java index ca2467b38..bffe5025d 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -20,8 +20,6 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.TinyProtocol; -import com.google.gson.Gson; -import com.google.gson.JsonObject; import de.steamwar.Reflection; import de.steamwar.command.*; import de.steamwar.core.authlib.AuthlibInjector; @@ -38,37 +36,23 @@ import de.steamwar.sql.internal.Statement; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.plugin.messaging.PluginMessageListener; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Collection; -import java.util.HashMap; -import java.util.Map; import java.util.logging.Level; -public class Core extends JavaPlugin implements PluginMessageListener, Listener { +public class Core extends JavaPlugin { public static final Message MESSAGE = new Message("SpigotCore", Core.class.getClassLoader()); - private static final String CHANNEL = "vv:proxy_details"; - private static final Gson GSON = new Gson(); - private static final Map playerVersions = new HashMap<>(); - public static int getVersion(){ return Reflection.MAJOR_VERSION; } - public static int getPlayerVersion(Player player) { - return playerVersions.getOrDefault(player, -1); - } - public static boolean isBedrockPlayer(Player player) { return player.getName().startsWith("."); } @@ -91,8 +75,7 @@ public class Core extends JavaPlugin implements PluginMessageListener, Listener @Override public void onEnable() { - this.getServer().getMessenger().registerIncomingPluginChannel(this, CHANNEL, this); - Bukkit.getPluginManager().registerEvents(this, this); + new PlayerVersion(); errorHandler = new ErrorHandler(); crashDetector = new CrashDetector(); @@ -151,20 +134,4 @@ public class Core extends JavaPlugin implements PluginMessageListener, Listener Statement.closeAll(); this.getServer().getMessenger().unregisterIncomingPluginChannel(this); } - - @Override - public void onPluginMessageReceived(String channel, Player player, byte[] bytes) { - if (!channel.equals(CHANNEL)) { - return; - } - - final JsonObject payload = GSON.fromJson(new String(bytes), JsonObject.class); - final String version = payload.get("versionName").getAsString(); - playerVersions.put(player, Integer.parseInt(version.split("-")[0].split("\\.")[1])); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onPlayerQuit(PlayerQuitEvent event) { - playerVersions.remove(event.getPlayer()); - } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/PlayerVersion.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/PlayerVersion.java new file mode 100644 index 000000000..8b73e9b47 --- /dev/null +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/PlayerVersion.java @@ -0,0 +1,65 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.core; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import org.bukkit.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.player.PlayerQuitEvent; +import org.bukkit.plugin.messaging.PluginMessageListener; + +import java.util.HashMap; +import java.util.Map; + +public class PlayerVersion implements PluginMessageListener, Listener { + + private static final String PLAYER_VERSION_CHANNEL = "vv:proxy_details"; + private static final Gson GSON = new Gson(); + private static final Map playerVersions = new HashMap<>(); + + public static int getVersion(Player player) { + return playerVersions.getOrDefault(player, -1); + } + + public PlayerVersion() { + Core.getInstance().getServer().getMessenger().registerIncomingPluginChannel(Core.getInstance(), PLAYER_VERSION_CHANNEL, this); + Bukkit.getPluginManager().registerEvents(this, Core.getInstance()); + } + + @Override + public void onPluginMessageReceived(String channel, Player player, byte[] bytes) { + if (!channel.equals(PLAYER_VERSION_CHANNEL)) { + return; + } + + final JsonObject payload = GSON.fromJson(new String(bytes), JsonObject.class); + final String version = payload.get("versionName").getAsString(); + playerVersions.put(player, Integer.parseInt(version.split("-")[0].split("\\.")[1])); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onPlayerQuit(PlayerQuitEvent event) { + playerVersions.remove(event.getPlayer()); + } +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java index 6d84963ca..0a6c128ca 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java @@ -105,11 +105,6 @@ public class WorldEditRenderer implements Listener { } } - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) { - renderPlayer(event.getPlayer()); - } - @EventHandler public void onPlayerMove(PlayerMoveEvent event) { if(event.getPlayer().getItemInHand().getType() == WAND) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererWrapper.java index fd6c0ea1c..c303ed199 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererWrapper.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererWrapper.java @@ -27,7 +27,7 @@ public interface WorldEditRendererWrapper { WorldEditRendererWrapper impl = VersionDependent.getVersionImpl(Core.getInstance()); static void safeDraw(Player player, Player owner, boolean clipboard, Vector pos1, Vector pos2) { - if (Core.isBedrockPlayer(player) || Core.getPlayerVersion(player) < 20) { + if (Core.isBedrockPlayer(player) || PlayerVersion.getVersion(player) < 20) { fallback.draw(player, owner, clipboard, pos1, pos2); } else { impl.draw(player, owner, clipboard, pos1, pos2); From c6ecab5aa8298bdcda7ef7b0c6d519bf6b54aa62 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 26 Jun 2025 21:01:00 +0200 Subject: [PATCH 070/153] Fix some stuff --- .../core/WorldEditRendererWrapper20.java | 49 ++++---------- .../core/WorldEditRendererWrapper8.java | 4 +- .../core/WorldEditRendererWrapper9.java | 42 ++++++------ .../de/steamwar/core/WorldEditRenderer.java | 66 +++++++++---------- .../core/WorldEditRendererCUIEditor.java | 9 +-- .../core/WorldEditRendererWrapper.java | 10 +-- 6 files changed, 74 insertions(+), 106 deletions(-) diff --git a/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java b/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java index 58d8c4e93..36ded8eff 100644 --- a/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java +++ b/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java @@ -26,7 +26,6 @@ import org.bukkit.block.data.BlockData; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -63,31 +62,26 @@ public class WorldEditRendererWrapper20 implements WorldEditRendererWrapper { } private static final Map servers = new HashMap<>(); - private static final Map> boxes = new HashMap<>(); + private static final Map boxes = new HashMap<>(); @Override - public void draw(Player player, Player owner, boolean clipboard, Vector pos1, Vector pos2) { + public void draw(Player player, boolean scheduled, boolean clipboard, Vector pos1, Vector pos2) { REntityServer server = servers.computeIfAbsent(player, __ -> { REntityServer entityServer = new REntityServer(); entityServer.addPlayer(player); return entityServer; }); - WorldEditRendererCUIEditor.Type type; - if (player == owner) { - type = clipboard ? WorldEditRendererCUIEditor.Type.CLIPBOARD : WorldEditRendererCUIEditor.Type.SELECTION; - } else { - type = clipboard ? WorldEditRendererCUIEditor.Type.CLIPBOARD_OTHER : WorldEditRendererCUIEditor.Type.SELECTION_OTHER; - } + WorldEditRendererCUIEditor.Type type = clipboard ? WorldEditRendererCUIEditor.Type.CLIPBOARD : WorldEditRendererCUIEditor.Type.SELECTION; float width = type.getWidth(player).value; Material material = type.getMaterial(player); if (material == Material.BARRIER) { - hide(player, owner, clipboard, true); + hide(player, clipboard, true); return; } BlockData block = material.createBlockData(); - BoxPair boxPair = boxes.computeIfAbsent(player, __ -> new HashMap<>()).computeIfAbsent(owner, __ -> new BoxPair()); + BoxPair boxPair = boxes.computeIfAbsent(player, __ -> new BoxPair()); CWireframe box = boxPair.get(clipboard); if (box == null) { box = new CWireframe(server); @@ -107,35 +101,18 @@ public class WorldEditRendererWrapper20 implements WorldEditRendererWrapper { } @Override - public void hide(Player player, Player owner, boolean clipboard, boolean hide) { - Map pairs = boxes.getOrDefault(player, Collections.emptyMap()); - if (owner != null) { - BoxPair boxPair = pairs.get(owner); - if (boxPair == null) return; - CWireframe box = boxPair.get(clipboard); - if (box != null) box.hide(hide); - } else { - pairs.values().forEach(boxPair -> { - CWireframe box = boxPair.get(clipboard); - if (box != null) box.hide(hide); - }); - } + public void hide(Player player, boolean clipboard, boolean hide) { + BoxPair boxPair = boxes.get(player); + if (boxPair == null) return; + CWireframe box = boxPair.get(clipboard); + if (box == null) return; + box.hide(hide); } @Override public void remove(Player player) { - Map removed = boxes.remove(player); - if (removed != null) { - removed.values().forEach(boxPair -> { - boxPair.die(); - }); - } - boxes.values().forEach(map -> { - BoxPair boxPair = map.remove(player); - if (boxPair == null) return; - boxPair.die(); - }); - + BoxPair boxPair = boxes.remove(player); + if (boxPair != null) boxPair.die(); REntityServer server = servers.remove(player); if (server != null) server.close(); } diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditRendererWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditRendererWrapper8.java index 3a9042ed7..68f64c46f 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditRendererWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditRendererWrapper8.java @@ -25,7 +25,7 @@ import org.bukkit.util.Vector; public class WorldEditRendererWrapper8 implements WorldEditRendererWrapper { @Override - public void draw(Player player, Player owner, boolean clipboard, Vector pos1, Vector pos2) { + public void draw(Player player, boolean scheduled, boolean clipboard, Vector pos1, Vector pos2) { } @Override @@ -33,7 +33,7 @@ public class WorldEditRendererWrapper8 implements WorldEditRendererWrapper { } @Override - public void hide(Player player, Player owner, boolean clipboard, boolean hide) { + public void hide(Player player, boolean clipboard, boolean hide) { } @Override diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRendererWrapper9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRendererWrapper9.java index 579b5f148..5da6104a8 100644 --- a/SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRendererWrapper9.java +++ b/SpigotCore/SpigotCore_9/src/de/steamwar/core/WorldEditRendererWrapper9.java @@ -34,34 +34,32 @@ public class WorldEditRendererWrapper9 implements WorldEditRendererWrapper { private static final Vector STEPS = new Vector(STEP_SIZE, STEP_SIZE, STEP_SIZE); @Override - public void draw(Player player, Player owner, boolean clipboard, Vector min, Vector max) { + public void draw(Player player, boolean scheduled, boolean clipboard, Vector min, Vector max) { + if (!scheduled) return; + max = max.clone().add(ONES); - drawLine(player, owner, clipboard, new Vector(min.getX(), min.getY(), min.getZ()), new Vector(max.getX(), min.getY(), min.getZ())); - drawLine(player, owner, clipboard, new Vector(min.getX(), max.getY(), min.getZ()), new Vector(max.getX(), max.getY(), min.getZ())); - drawLine(player, owner, clipboard, new Vector(min.getX(), min.getY(), max.getZ()), new Vector(max.getX(), min.getY(), max.getZ())); - drawLine(player, owner, clipboard, new Vector(min.getX(), max.getY(), max.getZ()), new Vector(max.getX(), max.getY(), max.getZ())); + drawLine(player, clipboard, new Vector(min.getX(), min.getY(), min.getZ()), new Vector(max.getX(), min.getY(), min.getZ())); + drawLine(player, clipboard, new Vector(min.getX(), max.getY(), min.getZ()), new Vector(max.getX(), max.getY(), min.getZ())); + drawLine(player, clipboard, new Vector(min.getX(), min.getY(), max.getZ()), new Vector(max.getX(), min.getY(), max.getZ())); + drawLine(player, clipboard, new Vector(min.getX(), max.getY(), max.getZ()), new Vector(max.getX(), max.getY(), max.getZ())); - drawLine(player, owner, clipboard, new Vector(min.getX(), min.getY(), min.getZ()), new Vector(min.getX(), max.getY(), min.getZ())); - drawLine(player, owner, clipboard, new Vector(max.getX(), min.getY(), min.getZ()), new Vector(max.getX(), max.getY(), min.getZ())); - drawLine(player, owner, clipboard, new Vector(min.getX(), min.getY(), max.getZ()), new Vector(min.getX(), max.getY(), max.getZ())); - drawLine(player, owner, clipboard, new Vector(max.getX(), min.getY(), max.getZ()), new Vector(max.getX(), max.getY(), max.getZ())); + drawLine(player, clipboard, new Vector(min.getX(), min.getY(), min.getZ()), new Vector(min.getX(), max.getY(), min.getZ())); + drawLine(player, clipboard, new Vector(max.getX(), min.getY(), min.getZ()), new Vector(max.getX(), max.getY(), min.getZ())); + drawLine(player, clipboard, new Vector(min.getX(), min.getY(), max.getZ()), new Vector(min.getX(), max.getY(), max.getZ())); + drawLine(player, clipboard, new Vector(max.getX(), min.getY(), max.getZ()), new Vector(max.getX(), max.getY(), max.getZ())); - drawLine(player, owner, clipboard, new Vector(min.getX(), min.getY(), min.getZ()), new Vector(min.getX(), min.getY(), max.getZ())); - drawLine(player, owner, clipboard, new Vector(max.getX(), min.getY(), min.getZ()), new Vector(max.getX(), min.getY(), max.getZ())); - drawLine(player, owner, clipboard, new Vector(min.getX(), max.getY(), min.getZ()), new Vector(min.getX(), max.getY(), max.getZ())); - drawLine(player, owner, clipboard, new Vector(max.getX(), max.getY(), min.getZ()), new Vector(max.getX(), max.getY(), max.getZ())); + drawLine(player, clipboard, new Vector(min.getX(), min.getY(), min.getZ()), new Vector(min.getX(), min.getY(), max.getZ())); + drawLine(player, clipboard, new Vector(max.getX(), min.getY(), min.getZ()), new Vector(max.getX(), min.getY(), max.getZ())); + drawLine(player, clipboard, new Vector(min.getX(), max.getY(), min.getZ()), new Vector(min.getX(), max.getY(), max.getZ())); + drawLine(player, clipboard, new Vector(max.getX(), max.getY(), min.getZ()), new Vector(max.getX(), max.getY(), max.getZ())); } - private void drawLine(Player player, Player owner, boolean clipboard, Vector min, Vector max) { + private void drawLine(Player player, boolean clipboard, Vector min, Vector max) { Particle particle; - if (player == owner) { - if (clipboard) { - particle = TrickyParticleWrapper.impl.getVillagerHappy(); - } else { - particle = Particle.DRAGON_BREATH; - } + if (clipboard) { + particle = TrickyParticleWrapper.impl.getVillagerHappy(); } else { - particle = Particle.TOWN_AURA; + particle = Particle.DRAGON_BREATH; } Vector stepSize = max.clone().subtract(min).normalize().multiply(STEPS); @@ -85,7 +83,7 @@ public class WorldEditRendererWrapper9 implements WorldEditRendererWrapper { } @Override - public void hide(Player player, Player owner, boolean clipboard, boolean hide) { + public void hide(Player player, boolean clipboard, boolean hide) { } @Override diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java index 0a6c128ca..5e3595121 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java @@ -47,22 +47,20 @@ public class WorldEditRenderer implements Listener { we = WorldEditWrapper.getWorldEditPlugin(); Bukkit.getPluginManager().registerEvents(this, Core.getInstance()); - Bukkit.getScheduler().runTaskTimer(Core.getInstance(), this::render, 20, 20); + Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> { + for (Player player : Bukkit.getOnlinePlayers()) { + renderPlayer(player, true); + } + }, 20, 20); } - private void render() { - for(Player player : Bukkit.getOnlinePlayers()) { - renderPlayer(player); - } - } - - private void renderPlayer(Player player) { + private void renderPlayer(Player player, boolean scheduled) { LocalSession session = we.getSession(player); - renderClipboard(player, session); - renderRegion(player, session); + renderClipboard(player, session, scheduled); + renderRegion(player, session, scheduled); } - private void renderClipboard(Player player, LocalSession session) { + private void renderClipboard(Player player, LocalSession session, boolean scheduled) { try { Clipboard clipboard = session.getClipboard().getClipboard(); Vector pos = player.getLocation().toVector(); @@ -72,36 +70,34 @@ public class WorldEditRenderer implements Listener { Vector b = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMaximum(region).subtract(WorldEditWrapper.impl.getOrigin(clipboard)), transform).add(pos); a = new Vector(a.getBlockX(), a.getBlockY(), a.getBlockZ()); b = new Vector(b.getBlockX(), b.getBlockY(), b.getBlockZ()); - drawCuboid(Vector.getMinimum(a, b), Vector.getMaximum(a, b), true, player); + drawCuboid(Vector.getMinimum(a, b), Vector.getMaximum(a, b), scheduled, true, player); } catch (EmptyClipboardException e) { - WorldEditRendererWrapper.impl.hide(player, player, true, true); + WorldEditRendererWrapper.impl.hide(player, true, true); } } - private void renderRegion(Player player, LocalSession session) { + private void renderRegion(Player player, LocalSession session, boolean scheduled) { World world = session.getSelectionWorld(); if(world != null) { RegionSelector regionSelector = session.getRegionSelector(world); try { Region region = regionSelector.getRegion(); - drawCuboid(WorldEditWrapper.impl.getMinimum(region), WorldEditWrapper.impl.getMaximum(region), false, player); + drawCuboid(WorldEditWrapper.impl.getMinimum(region), WorldEditWrapper.impl.getMaximum(region), scheduled, false, player); } catch (IncompleteRegionException e) { - WorldEditRendererWrapper.impl.hide(player, player, false, true); + WorldEditRendererWrapper.impl.hide(player, false, true); } } } - private void drawCuboid(Vector min, Vector max, boolean clipboard, Player owner) { - for (Player player : Bukkit.getOnlinePlayers()) { - //noinspection deprecation - if(player.getItemInHand().getType() != WAND) { - WorldEditRendererWrapper.impl.hide(player, owner, true, true); - WorldEditRendererWrapper.impl.hide(player, owner, false, true); - } else { - WorldEditRendererWrapper.impl.hide(player, owner, true, false); - WorldEditRendererWrapper.impl.hide(player, owner, false, false); - WorldEditRendererWrapper.safeDraw(player, owner, clipboard, min, max); - } + private void drawCuboid(Vector min, Vector max, boolean scheduled, boolean clipboard, Player owner) { + //noinspection deprecation + if(owner.getItemInHand().getType() != WAND) { + WorldEditRendererWrapper.impl.hide(owner, true, true); + WorldEditRendererWrapper.impl.hide(owner, false, true); + } else { + WorldEditRendererWrapper.impl.hide(owner, true, false); + WorldEditRendererWrapper.impl.hide(owner, false, false); + WorldEditRendererWrapper.safeDraw(owner, scheduled, clipboard, min, max); } } @@ -110,20 +106,20 @@ public class WorldEditRenderer implements Listener { if(event.getPlayer().getItemInHand().getType() == WAND) { WorldEditRendererWrapper.impl.tick(event.getPlayer()); } - renderClipboard(event.getPlayer(), we.getSession(event.getPlayer())); + renderClipboard(event.getPlayer(), we.getSession(event.getPlayer()), false); } @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { - renderRegion(event.getPlayer(), we.getSession(event.getPlayer())); + renderRegion(event.getPlayer(), we.getSession(event.getPlayer()), false); }, 0); } @EventHandler public void onBlockBreak(BlockBreakEvent event) { Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { - renderRegion(event.getPlayer(), we.getSession(event.getPlayer())); + renderRegion(event.getPlayer(), we.getSession(event.getPlayer()), false); }, 0); } @@ -132,8 +128,8 @@ public class WorldEditRenderer implements Listener { if (event.getMessage().startsWith("//")) { Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { LocalSession session = we.getSession(event.getPlayer()); - renderRegion(event.getPlayer(), session); - renderClipboard(event.getPlayer(), session); + renderRegion(event.getPlayer(), session, false); + renderClipboard(event.getPlayer(), session, false); }, 5); } } @@ -141,19 +137,19 @@ public class WorldEditRenderer implements Listener { @EventHandler public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) { Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { - renderPlayer(event.getPlayer()); + renderPlayer(event.getPlayer(), false); }, 1); } @EventHandler public void onPlayerDropItem(PlayerDropItemEvent event) { - renderPlayer(event.getPlayer()); + renderPlayer(event.getPlayer(), false); } @EventHandler public void onPlayerItemHeld(PlayerItemHeldEvent event) { Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { - renderPlayer(event.getPlayer()); + renderPlayer(event.getPlayer(), false); }, 1); } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererCUIEditor.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererCUIEditor.java index 46fe53ded..d03fcf418 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererCUIEditor.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererCUIEditor.java @@ -41,8 +41,7 @@ public class WorldEditRendererCUIEditor { public enum Type { SELECTION("cui_selection_material", "cui_selection_width", Material.PURPLE_CONCRETE, Width.LARGE), CLIPBOARD("cui_clipboard_material", "cui_clipboard_width", Material.LIME_CONCRETE, Width.LARGE), - SELECTION_OTHER("cui_selection_other_material", "cui_selection_other_width", Material.GRAY_CONCRETE, Width.SLIM), - CLIPBOARD_OTHER("cui_clipboard_other_material", "cui_clipboard_other_width", Material.GRAY_CONCRETE, Width.SLIM); + ; private final String configMaterial; private final String configWidth; @@ -103,10 +102,8 @@ public class WorldEditRendererCUIEditor { @Register public void cuiEditor(Player player) { SWInventory inv = new SWInventory(player, 9 * 2, Core.MESSAGE.parse("WORLDEDIT_CUI_TITLE", player)); - setElement(inv, player, 1, "WORLDEDIT_CUI_SELECTION", Type.SELECTION); - setElement(inv, player, 3, "WORLDEDIT_CUI_CLIPBOARD", Type.CLIPBOARD); - setElement(inv, player, 5, "WORLDEDIT_CUI_SELECTION_OTHER", Type.SELECTION_OTHER); - setElement(inv, player, 7, "WORLDEDIT_CUI_CLIPBOARD_OTHER", Type.CLIPBOARD_OTHER); + setElement(inv, player, 3, "WORLDEDIT_CUI_SELECTION", Type.SELECTION); + setElement(inv, player, 5, "WORLDEDIT_CUI_CLIPBOARD", Type.CLIPBOARD); inv.open(); } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererWrapper.java index c303ed199..79ed288bf 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererWrapper.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererWrapper.java @@ -26,19 +26,19 @@ public interface WorldEditRendererWrapper { WorldEditRendererWrapper fallback = VersionDependent.getVersionImpl(Core.getInstance(), 9); WorldEditRendererWrapper impl = VersionDependent.getVersionImpl(Core.getInstance()); - static void safeDraw(Player player, Player owner, boolean clipboard, Vector pos1, Vector pos2) { + static void safeDraw(Player player, boolean scheduled, boolean clipboard, Vector pos1, Vector pos2) { if (Core.isBedrockPlayer(player) || PlayerVersion.getVersion(player) < 20) { - fallback.draw(player, owner, clipboard, pos1, pos2); + fallback.draw(player, scheduled, clipboard, pos1, pos2); } else { - impl.draw(player, owner, clipboard, pos1, pos2); + impl.draw(player, scheduled, clipboard, pos1, pos2); } } - void draw(Player player, Player owner, boolean clipboard, Vector pos1, Vector pos2); + void draw(Player player, boolean scheduled, boolean clipboard, Vector pos1, Vector pos2); void tick(Player player); - void hide(Player player, Player owner, boolean clipboard, boolean hide); + void hide(Player player, boolean clipboard, boolean hide); void remove(Player player); } From 1fd8b3c4cb7ee65fa804c4418a042cded5945755 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 26 Jun 2025 21:52:07 +0200 Subject: [PATCH 071/153] Add ClientVersionPacket --- .../packets/server/ClientVersionPacket.java | 39 +++++++++++++++++++ .../src/de/steamwar/core/Core.java | 5 --- .../src/de/steamwar/core/PlayerVersion.java | 34 +++++++--------- .../core/WorldEditRendererWrapper.java | 2 +- .../listeners/VersionAnnouncer.java | 16 ++++++-- 5 files changed, 67 insertions(+), 29 deletions(-) create mode 100644 CommonCore/Network/src/de/steamwar/network/packets/server/ClientVersionPacket.java diff --git a/CommonCore/Network/src/de/steamwar/network/packets/server/ClientVersionPacket.java b/CommonCore/Network/src/de/steamwar/network/packets/server/ClientVersionPacket.java new file mode 100644 index 000000000..af0ba4eda --- /dev/null +++ b/CommonCore/Network/src/de/steamwar/network/packets/server/ClientVersionPacket.java @@ -0,0 +1,39 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.network.packets.server; + +import de.steamwar.network.packets.NetworkPacket; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.UUID; + +@EqualsAndHashCode(callSuper = true) +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class ClientVersionPacket extends NetworkPacket { + private static final long serialVersionUID = 3686482311704273200L; + + private UUID player; + private int version; +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java index bffe5025d..568c3e48e 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -35,7 +35,6 @@ import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.internal.Statement; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; @@ -53,10 +52,6 @@ public class Core extends JavaPlugin { return Reflection.MAJOR_VERSION; } - public static boolean isBedrockPlayer(Player player) { - return player.getName().startsWith("."); - } - private static JavaPlugin instance; public static JavaPlugin getInstance() { return instance; diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/PlayerVersion.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/PlayerVersion.java index 8b73e9b47..512df0d30 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/PlayerVersion.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/PlayerVersion.java @@ -19,47 +19,43 @@ package de.steamwar.core; -import com.google.gson.Gson; -import com.google.gson.JsonObject; +import de.steamwar.network.packets.PacketHandler; +import de.steamwar.network.packets.server.ClientVersionPacket; import org.bukkit.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.player.PlayerQuitEvent; -import org.bukkit.plugin.messaging.PluginMessageListener; import java.util.HashMap; import java.util.Map; +import java.util.UUID; -public class PlayerVersion implements PluginMessageListener, Listener { +public class PlayerVersion extends PacketHandler implements Listener { - private static final String PLAYER_VERSION_CHANNEL = "vv:proxy_details"; - private static final Gson GSON = new Gson(); - private static final Map playerVersions = new HashMap<>(); + private static final Map playerVersions = new HashMap<>(); public static int getVersion(Player player) { - return playerVersions.getOrDefault(player, -1); + return playerVersions.getOrDefault(player.getUniqueId(), -1); + } + + public static boolean isBedrock(Player player) { + return player.getName().startsWith("."); } public PlayerVersion() { - Core.getInstance().getServer().getMessenger().registerIncomingPluginChannel(Core.getInstance(), PLAYER_VERSION_CHANNEL, this); Bukkit.getPluginManager().registerEvents(this, Core.getInstance()); + register(); } - @Override - public void onPluginMessageReceived(String channel, Player player, byte[] bytes) { - if (!channel.equals(PLAYER_VERSION_CHANNEL)) { - return; - } - - final JsonObject payload = GSON.fromJson(new String(bytes), JsonObject.class); - final String version = payload.get("versionName").getAsString(); - playerVersions.put(player, Integer.parseInt(version.split("-")[0].split("\\.")[1])); + @Handler + public void handlePacket(ClientVersionPacket clientVersionPacket) { + playerVersions.put(clientVersionPacket.getPlayer(), clientVersionPacket.getVersion()); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerQuit(PlayerQuitEvent event) { - playerVersions.remove(event.getPlayer()); + playerVersions.remove(event.getPlayer().getUniqueId()); } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererWrapper.java index 79ed288bf..2439d40d1 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererWrapper.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererWrapper.java @@ -27,7 +27,7 @@ public interface WorldEditRendererWrapper { WorldEditRendererWrapper impl = VersionDependent.getVersionImpl(Core.getInstance()); static void safeDraw(Player player, boolean scheduled, boolean clipboard, Vector pos1, Vector pos2) { - if (Core.isBedrockPlayer(player) || PlayerVersion.getVersion(player) < 20) { + if (PlayerVersion.isBedrock(player) || PlayerVersion.getVersion(player) < 20) { fallback.draw(player, scheduled, clipboard, pos1, pos2); } else { impl.draw(player, scheduled, clipboard, pos1, pos2); diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/VersionAnnouncer.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/VersionAnnouncer.java index c28a8fee1..4976213fe 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/VersionAnnouncer.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/VersionAnnouncer.java @@ -27,19 +27,27 @@ import com.velocitypowered.api.proxy.server.ServerInfo; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.velocity.platform.VelocityViaConfig; import de.steamwar.messages.Chatter; +import de.steamwar.network.packets.server.ClientVersionPacket; import de.steamwar.persistent.Subserver; +import de.steamwar.velocitycore.network.NetworkSender; public class VersionAnnouncer extends BasicListener { @Subscribe public void postConnect(ServerConnectedEvent e) { ServerInfo server = e.getServer().getServerInfo(); - if(!Subserver.isBuild(Subserver.getSubserver(server))) - return; - Player player = e.getPlayer(); int serverVersion = ((VelocityViaConfig) Via.getConfig()).getVelocityServerProtocols().get(server.getName()); - if(Via.getAPI().getPlayerVersion(player) == serverVersion) + + int playerVersion = Via.getAPI().getPlayerVersion(player); + String version = ProtocolVersion.getProtocolVersion(playerVersion).getVersionIntroducedIn(); + // PluginChannel 'vv:proxy_details' from ViaVersion apparently does not work any longer! + NetworkSender.send(player, new ClientVersionPacket(player.getUniqueId(), Integer.parseInt(version.split("-")[0].split("\\.")[1]))); + + if(playerVersion == serverVersion) + return; + + if(!Subserver.isBuild(Subserver.getSubserver(server))) return; player.sendActionBar(Chatter.of(player).parse("SERVER_VERSION", ProtocolVersion.getProtocolVersion(serverVersion).getMostRecentSupportedVersion())); From c6826788279dc1b1bee39fd1c7a6f2cfd572cfad Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 26 Jun 2025 21:57:44 +0200 Subject: [PATCH 072/153] Add ClientVersionPacket Update VersionAnnouncer --- .../network/packets/server/ClientVersionPacket.java | 6 ++---- .../steamwar/velocitycore/listeners/VersionAnnouncer.java | 8 +++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CommonCore/Network/src/de/steamwar/network/packets/server/ClientVersionPacket.java b/CommonCore/Network/src/de/steamwar/network/packets/server/ClientVersionPacket.java index af0ba4eda..c8f434469 100644 --- a/CommonCore/Network/src/de/steamwar/network/packets/server/ClientVersionPacket.java +++ b/CommonCore/Network/src/de/steamwar/network/packets/server/ClientVersionPacket.java @@ -20,10 +20,7 @@ package de.steamwar.network.packets.server; import de.steamwar.network.packets.NetworkPacket; -import lombok.AllArgsConstructor; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import java.util.UUID; @@ -31,6 +28,7 @@ import java.util.UUID; @Getter @AllArgsConstructor @NoArgsConstructor +@ToString public class ClientVersionPacket extends NetworkPacket { private static final long serialVersionUID = 3686482311704273200L; diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/VersionAnnouncer.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/VersionAnnouncer.java index 4976213fe..cf39f8433 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/VersionAnnouncer.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/VersionAnnouncer.java @@ -29,8 +29,12 @@ import com.viaversion.viaversion.velocity.platform.VelocityViaConfig; import de.steamwar.messages.Chatter; import de.steamwar.network.packets.server.ClientVersionPacket; import de.steamwar.persistent.Subserver; +import de.steamwar.velocitycore.VelocityCore; import de.steamwar.velocitycore.network.NetworkSender; +import java.time.Duration; +import java.time.temporal.ChronoUnit; + public class VersionAnnouncer extends BasicListener { @Subscribe @@ -42,7 +46,9 @@ public class VersionAnnouncer extends BasicListener { int playerVersion = Via.getAPI().getPlayerVersion(player); String version = ProtocolVersion.getProtocolVersion(playerVersion).getVersionIntroducedIn(); // PluginChannel 'vv:proxy_details' from ViaVersion apparently does not work any longer! - NetworkSender.send(player, new ClientVersionPacket(player.getUniqueId(), Integer.parseInt(version.split("-")[0].split("\\.")[1]))); + VelocityCore.schedule(() -> { + NetworkSender.send(player, new ClientVersionPacket(player.getUniqueId(), Integer.parseInt(version.split("-")[0].split("\\.")[1]))); + }).delay(Duration.of(100, ChronoUnit.MILLIS)).schedule(); if(playerVersion == serverVersion) return; From 3f7cd48f27640a4c11c1b02a32d7f59351883a19 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 26 Jun 2025 22:01:56 +0200 Subject: [PATCH 073/153] Update sensible defaults for WorldEditRendererCUIEditor --- .../src/de/steamwar/core/WorldEditRendererCUIEditor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererCUIEditor.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererCUIEditor.java index d03fcf418..e50eac9d3 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererCUIEditor.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRendererCUIEditor.java @@ -39,8 +39,8 @@ public class WorldEditRendererCUIEditor { @AllArgsConstructor public enum Type { - SELECTION("cui_selection_material", "cui_selection_width", Material.PURPLE_CONCRETE, Width.LARGE), - CLIPBOARD("cui_clipboard_material", "cui_clipboard_width", Material.LIME_CONCRETE, Width.LARGE), + SELECTION("cui_selection_material", "cui_selection_width", Material.PURPLE_CONCRETE, Width.MEDIUM), + CLIPBOARD("cui_clipboard_material", "cui_clipboard_width", Material.LIME_CONCRETE, Width.SLIM), ; private final String configMaterial; From b6279fd7fa5918c10ac81251d6e1e975abc43d04 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 26 Jun 2025 22:06:38 +0200 Subject: [PATCH 074/153] Remove useless line of code --- SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java | 1 - 1 file changed, 1 deletion(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java index 568c3e48e..c2086b0b6 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -127,6 +127,5 @@ public class Core extends JavaPlugin { errorHandler.unregister(); if(crashDetector.onMainThread()) Statement.closeAll(); - this.getServer().getMessenger().unregisterIncomingPluginChannel(this); } } From 1f1f99f8f318944b008b843b6533f4f63fec4613 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 26 Jun 2025 23:38:19 +0200 Subject: [PATCH 075/153] Adjust advancing team logic in EventRelation to fix `fromPlace` handling --- CommonCore/SQL/src/de/steamwar/sql/EventRelation.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/EventRelation.java b/CommonCore/SQL/src/de/steamwar/sql/EventRelation.java index 28c756eec..d9fde245f 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/EventRelation.java +++ b/CommonCore/SQL/src/de/steamwar/sql/EventRelation.java @@ -133,7 +133,7 @@ public class EventRelation { public Optional getAdvancingTeam() { if (fromType == FromType.FIGHT) { - if (fromPlace == 1) { + if (fromPlace == 0) { return getFromFight().flatMap(EventFight::getWinner); } else { return getFromFight().flatMap(EventFight::getLosser); @@ -141,7 +141,9 @@ public class EventRelation { } else if (fromType == FromType.GROUP) { return getFromGroup().map(EventGroup::calculatePoints) .flatMap(points -> points.entrySet().stream() - .max(Map.Entry.comparingByValue()) + .sorted(Map.Entry.comparingByValue()) + .skip(fromPlace) + .findFirst() .map(Map.Entry::getKey)); } else { return Optional.empty(); From bc5e781810f33ad136bfab0169c6286104406a5b Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 28 Jun 2025 13:26:05 +0200 Subject: [PATCH 076/153] Hotfix VersionAnnouncer --- .../src/de/steamwar/network/CoreNetworkHandler.java | 3 +-- .../velocitycore/listeners/VersionAnnouncer.java | 13 ++++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/network/CoreNetworkHandler.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/network/CoreNetworkHandler.java index 50ee9fcb3..8edf5fc0b 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/network/CoreNetworkHandler.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/network/CoreNetworkHandler.java @@ -74,8 +74,7 @@ public class CoreNetworkHandler extends PacketHandler { @Handler public void handlePlayerSkinResponse(PlayerSkinResponsePacket packet) { - Property property = RPlayer.SKIN_DATA_PROMISES.get(packet.getUuid()); - if (property == null) return; + if (!RPlayer.SKIN_DATA_PROMISES.containsKey(packet.getUuid())) return; RPlayer.SKIN_DATA_PROMISES.put(packet.getUuid(), new Property("textures", packet.getSkin(), packet.getSignature())); } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/VersionAnnouncer.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/VersionAnnouncer.java index cf39f8433..5204d2589 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/VersionAnnouncer.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/VersionAnnouncer.java @@ -44,11 +44,14 @@ public class VersionAnnouncer extends BasicListener { int serverVersion = ((VelocityViaConfig) Via.getConfig()).getVelocityServerProtocols().get(server.getName()); int playerVersion = Via.getAPI().getPlayerVersion(player); - String version = ProtocolVersion.getProtocolVersion(playerVersion).getVersionIntroducedIn(); - // PluginChannel 'vv:proxy_details' from ViaVersion apparently does not work any longer! - VelocityCore.schedule(() -> { - NetworkSender.send(player, new ClientVersionPacket(player.getUniqueId(), Integer.parseInt(version.split("-")[0].split("\\.")[1]))); - }).delay(Duration.of(100, ChronoUnit.MILLIS)).schedule(); + ProtocolVersion protocolVersion = ProtocolVersion.getProtocolVersion(serverVersion); + if (protocolVersion.isSupported()) { + // PluginChannel 'vv:proxy_details' from ViaVersion apparently does not work any longer! + VelocityCore.schedule(() -> { + String[] strings = protocolVersion.getVersionIntroducedIn().split("\\."); + NetworkSender.send(player, new ClientVersionPacket(player.getUniqueId(), Integer.parseInt(strings[1]))); + }).delay(Duration.of(100, ChronoUnit.MILLIS)).schedule(); + } if(playerVersion == serverVersion) return; From d06faa5d18db93033efa3f08f4b200201eee113a Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 28 Jun 2025 13:32:50 +0200 Subject: [PATCH 077/153] Fix 'java.lang.reflect.InvocationTargetException' for RPlayer being initialised --- .../src/de/steamwar/entity/RPlayer.java | 11 ++--------- .../de/steamwar/network/CoreNetworkHandler.java | 14 +++++++++++--- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java index 2575a7786..5edbbeebf 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java @@ -26,6 +26,7 @@ import de.steamwar.core.BountifulWrapper; import de.steamwar.core.Core; import de.steamwar.core.FlatteningWrapper; import de.steamwar.core.ProtocolWrapper; +import de.steamwar.network.CoreNetworkHandler; import de.steamwar.network.NetworkSender; import de.steamwar.network.packets.common.PlayerSkinRequestPacket; import lombok.Getter; @@ -34,7 +35,6 @@ import org.bukkit.Location; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; -import java.util.LinkedHashMap; import java.util.Map; import java.util.UUID; import java.util.function.Consumer; @@ -75,15 +75,8 @@ public class RPlayer extends REntity { server.addEntity(this); } - public static final Map SKIN_DATA_PROMISES = new LinkedHashMap() { - @Override - protected boolean removeEldestEntry(Map.Entry eldest) { - return size() > 100; - } - }; - private GameProfile getGameProfile() { - Property skinData = SKIN_DATA_PROMISES.computeIfAbsent(uuid, __ -> { + Property skinData = CoreNetworkHandler.SKIN_DATA_PROMISES.computeIfAbsent(uuid, __ -> { NetworkSender.sendOrQueue(new PlayerSkinRequestPacket(uuid)); return new Property("textures", null, null); }); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/network/CoreNetworkHandler.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/network/CoreNetworkHandler.java index 8edf5fc0b..d2b9016da 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/network/CoreNetworkHandler.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/network/CoreNetworkHandler.java @@ -21,7 +21,6 @@ package de.steamwar.network; import com.mojang.authlib.properties.Property; import de.steamwar.core.BountifulWrapper; -import de.steamwar.entity.RPlayer; import de.steamwar.network.handlers.InventoryHandler; import de.steamwar.network.packets.PacketHandler; import de.steamwar.network.packets.common.PlayerSkinResponsePacket; @@ -31,6 +30,8 @@ import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import java.util.LinkedHashMap; +import java.util.Map; import java.util.UUID; public class CoreNetworkHandler extends PacketHandler { @@ -72,9 +73,16 @@ public class CoreNetworkHandler extends PacketHandler { SteamwarUser.invalidate(packet.getPlayerId()); } + public static final Map SKIN_DATA_PROMISES = new LinkedHashMap() { + @Override + protected boolean removeEldestEntry(Map.Entry eldest) { + return size() > 100; + } + }; + @Handler public void handlePlayerSkinResponse(PlayerSkinResponsePacket packet) { - if (!RPlayer.SKIN_DATA_PROMISES.containsKey(packet.getUuid())) return; - RPlayer.SKIN_DATA_PROMISES.put(packet.getUuid(), new Property("textures", packet.getSkin(), packet.getSignature())); + if (!SKIN_DATA_PROMISES.containsKey(packet.getUuid())) return; + SKIN_DATA_PROMISES.put(packet.getUuid(), new Property("textures", packet.getSkin(), packet.getSignature())); } } From 1bb15d9551dc4ace662525e97621eb0b0411e5d3 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 28 Jun 2025 14:14:55 +0200 Subject: [PATCH 078/153] Fix RPlayer skin data --- .../src/de/steamwar/entity/RPlayer.java | 15 ++++++++++----- .../src/de/steamwar/network/NetworkSender.java | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java index 5edbbeebf..0c383bfd9 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java @@ -40,7 +40,6 @@ import java.util.UUID; import java.util.function.Consumer; import java.util.function.Function; -@Getter public class RPlayer extends REntity { private static int skinPartsIndex() { @@ -65,7 +64,9 @@ public class RPlayer extends REntity { private static final Object skinPartsDataWatcher = BountifulWrapper.impl.getDataWatcherObject(skinPartsIndex(), Byte.class); + @Getter private final UUID actualUUID; + @Getter private final String name; public RPlayer(REntityServer server, UUID uuid, String name, Location location) { @@ -76,8 +77,8 @@ public class RPlayer extends REntity { } private GameProfile getGameProfile() { - Property skinData = CoreNetworkHandler.SKIN_DATA_PROMISES.computeIfAbsent(uuid, __ -> { - NetworkSender.sendOrQueue(new PlayerSkinRequestPacket(uuid)); + Property skinData = CoreNetworkHandler.SKIN_DATA_PROMISES.computeIfAbsent(actualUUID, __ -> { + NetworkSender.sendOrQueue(new PlayerSkinRequestPacket(actualUUID)); return new Property("textures", null, null); }); if (skinData.getValue() != null) { @@ -89,9 +90,12 @@ public class RPlayer extends REntity { } } + private GameProfile saved; + @Override void list(Consumer packetSink) { - packetSink.accept(ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.ADD, getGameProfile(), GameMode.CREATIVE)); + saved = getGameProfile(); + packetSink.accept(ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.ADD, saved, GameMode.CREATIVE)); } @Override @@ -108,7 +112,8 @@ public class RPlayer extends REntity { @Override void delist(Consumer packetSink) { - packetSink.accept(ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.REMOVE, getGameProfile(), GameMode.CREATIVE)); + if (saved == null) saved = getGameProfile(); + packetSink.accept(ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.REMOVE, saved, GameMode.CREATIVE)); } private static final Class namedSpawnPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundAddPlayerPacket"); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/network/NetworkSender.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/network/NetworkSender.java index 8000ff23f..197efd645 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/network/NetworkSender.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/network/NetworkSender.java @@ -44,7 +44,7 @@ public class NetworkSender implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { - if (!Bukkit.getOnlinePlayers().isEmpty()) { + if (Bukkit.getOnlinePlayers().size() > 1) { return; } Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { From bd9451f2aaf8812b0f937cae5880fb3f3203b03a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 29 Jun 2025 11:22:41 +0200 Subject: [PATCH 079/153] Fix Backend --- .../src/de/steamwar/routes/EventFights.kt | 2 +- WebsiteBackend/src/de/steamwar/routes/Page.kt | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/WebsiteBackend/src/de/steamwar/routes/EventFights.kt b/WebsiteBackend/src/de/steamwar/routes/EventFights.kt index d19746863..2f27b7e40 100644 --- a/WebsiteBackend/src/de/steamwar/routes/EventFights.kt +++ b/WebsiteBackend/src/de/steamwar/routes/EventFights.kt @@ -110,7 +110,7 @@ fun Route.configureEventFightRoutes() { fight.spectatePort ) if (fight.group != null) { - eventFight.groupId = fight.group + eventFight.setGroup(fight.group) } call.respond(HttpStatusCode.Created, ResponseEventFight(eventFight)) } diff --git a/WebsiteBackend/src/de/steamwar/routes/Page.kt b/WebsiteBackend/src/de/steamwar/routes/Page.kt index 083d8dc4f..2f8de4ee8 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Page.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Page.kt @@ -158,7 +158,6 @@ fun Route.configurePage() { }) } post { - val req = call.receive() if(req.path.startsWith("src/content/")) { call.respond(HttpStatusCode.BadRequest, "Invalid path") @@ -168,18 +167,20 @@ fun Route.configurePage() { contentType(ContentType.Application.Json) setBody(CreateGiteaPageRequest( "Create page ${req.path}", - Base64.getEncoder().encodeToString(""" + Base64.getEncoder().encodeToString(( + if (req.path.endsWith(".md")) """ --- - title: ${req.title ?: "[Enter Title]"} - description: [Enter Description] - key: ${req.slug ?: "[Enter Slug]"} + title: ${req.title?.removeSuffix(".md") ?: "Enter Title"} + description: Enter Description + key: ${req.slug?.lowercase()?.removeSuffix(".md") ?: "Enter Slug"} created: ${LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE)} tags: - test --- # ${req.path} - """.trimIndent().toByteArray()), + """ else "{}" + ).trimIndent().toByteArray()), call.request.queryParameters["branch"] ?: "master", Identity(call.principal()!!.user.userName, "admin-tool@steamwar.de" ))) From d2bb8e8e59a7eee0af825a819e0dbaa99d32e486 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 29 Jun 2025 19:53:42 +0200 Subject: [PATCH 080/153] Fix Relations --- CommonCore/SQL/src/de/steamwar/sql/EventRelation.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/EventRelation.java b/CommonCore/SQL/src/de/steamwar/sql/EventRelation.java index d9fde245f..7d1428058 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/EventRelation.java +++ b/CommonCore/SQL/src/de/steamwar/sql/EventRelation.java @@ -24,6 +24,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Optional; @@ -141,7 +142,7 @@ public class EventRelation { } else if (fromType == FromType.GROUP) { return getFromGroup().map(EventGroup::calculatePoints) .flatMap(points -> points.entrySet().stream() - .sorted(Map.Entry.comparingByValue()) + .sorted(Map.Entry.comparingByValue().reversed()) .skip(fromPlace) .findFirst() .map(Map.Entry::getKey)); From e4864e6eaf2beabc27f13ccd2255a7aa60184d8a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 29 Jun 2025 20:11:36 +0200 Subject: [PATCH 081/153] Add new changetype alias --- .../commands/schematiccommand/parts/ModifyPart.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ModifyPart.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ModifyPart.java index cee2cbc36..bc1e89c6a 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ModifyPart.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ModifyPart.java @@ -46,6 +46,7 @@ public class ModifyPart extends SWCommand { } @Register("changetype") + @Register("submit") public void changeType(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node) { TextComponent base = new TextComponent(); @@ -74,11 +75,13 @@ public class ModifyPart extends SWCommand { } @Register("changetype") + @Register("submit") public void changeType(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node, SchematicType type) { changeType(player, node, type, null); } @Register("changetype") + @Register("submit") public void changeType(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node, SchematicType type, SchematicCommand.Extend extend) { SchematicCommandUtils.changeType(player, node, type, extend); } From 39af920631de62777cfcbbb2dff39b2d728e9a48 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Mon, 30 Jun 2025 15:29:19 +0200 Subject: [PATCH 082/153] Remove TutorialSystem --- .../SQL/src/de/steamwar/sql/Tutorial.java | 94 ---------- TutorialSystem/build.gradle.kts | 28 --- .../de/steamwar/tutorial/TutorialSystem.java | 51 ------ .../tutorial/commands/BookReplaceCommand.java | 48 ----- .../tutorial/commands/TutorialCommand.java | 23 --- .../tutorial/commands/UnsignCommand.java | 21 --- .../tutorial/listener/BasicListener.java | 31 ---- .../steamwar/tutorial/listener/Joining.java | 40 ----- .../steamwar/tutorial/listener/RateSign.java | 48 ----- TutorialSystem/src/plugin.yml | 7 - .../steamwar/velocitycore/ServerStarter.java | 10 -- .../steamwar/velocitycore/VelocityCore.java | 1 - .../commands/TutorialCommand.java | 164 ------------------ 13 files changed, 566 deletions(-) delete mode 100644 CommonCore/SQL/src/de/steamwar/sql/Tutorial.java delete mode 100644 TutorialSystem/build.gradle.kts delete mode 100644 TutorialSystem/src/de/steamwar/tutorial/TutorialSystem.java delete mode 100644 TutorialSystem/src/de/steamwar/tutorial/commands/BookReplaceCommand.java delete mode 100644 TutorialSystem/src/de/steamwar/tutorial/commands/TutorialCommand.java delete mode 100644 TutorialSystem/src/de/steamwar/tutorial/commands/UnsignCommand.java delete mode 100644 TutorialSystem/src/de/steamwar/tutorial/listener/BasicListener.java delete mode 100644 TutorialSystem/src/de/steamwar/tutorial/listener/Joining.java delete mode 100644 TutorialSystem/src/de/steamwar/tutorial/listener/RateSign.java delete mode 100644 TutorialSystem/src/plugin.yml delete mode 100644 VelocityCore/src/de/steamwar/velocitycore/commands/TutorialCommand.java diff --git a/CommonCore/SQL/src/de/steamwar/sql/Tutorial.java b/CommonCore/SQL/src/de/steamwar/sql/Tutorial.java deleted file mode 100644 index 9febcba51..000000000 --- a/CommonCore/SQL/src/de/steamwar/sql/Tutorial.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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 . - */ - -package de.steamwar.sql; - -import de.steamwar.sql.internal.Field; -import de.steamwar.sql.internal.SelectStatement; -import de.steamwar.sql.internal.Statement; -import de.steamwar.sql.internal.Table; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.List; -import java.util.stream.Collectors; - -@AllArgsConstructor -public class Tutorial { - - private static final Table table = new Table<>(Tutorial.class); - private static final SelectStatement by_popularity = new SelectStatement<>(table, "SELECT t.*, AVG(r.Stars) AS Stars FROM Tutorial t LEFT OUTER JOIN TutorialRating r ON t.TutorialID = r.TutorialID WHERE t.Released = ? GROUP BY t.TutorialID ORDER BY SUM(r.Stars) DESC LIMIT ?, ?"); - private static final SelectStatement own = new SelectStatement<>(table, "SELECT t.*, AVG(r.Stars) AS Stars FROM Tutorial t LEFT OUTER JOIN TutorialRating r ON t.TutorialID = r.TutorialID WHERE t.Creator = ? GROUP BY t.TutorialID ORDER BY t.TutorialID ASC LIMIT ?, ?"); - private static final SelectStatement by_creator_name = new SelectStatement<>(table, "SELECT t.*, AVG(r.Stars) AS Stars FROM Tutorial t LEFT OUTER JOIN TutorialRating r ON t.TutorialID = r.TutorialID WHERE t.Creator = ? AND t.Name = ? GROUP BY t.TutorialID"); - private static final SelectStatement by_id = new SelectStatement<>(table, "SELECT t.*, AVG(r.Stars) AS Stars FROM Tutorial t LEFT OUTER JOIN TutorialRating r ON t.TutorialID = r.TutorialID WHERE t.TutorialID = ? GROUP BY t.TutorialID"); - private static final Statement rate = new Statement("INSERT INTO TutorialRating (TutorialID, UserID, Stars) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Stars = VALUES(Stars)"); - private static final Statement create = new Statement("INSERT INTO Tutorial (Creator, Name, Item) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Item = VALUES(Item), Released = 0"); - private static final Statement release = table.update(Table.PRIMARY, "released"); - private static final Statement delete = table.delete(Table.PRIMARY); - - public static List getPage(int page, int elementsPerPage, boolean released) { - List tutorials = by_popularity.listSelect(released, page * elementsPerPage, elementsPerPage); - SteamwarUser.batchCache(tutorials.stream().map(tutorial -> tutorial.creator).collect(Collectors.toSet())); - return tutorials; - } - - public static List getOwn(int user, int page, int elementsPerPage) { - return own.listSelect(user, page * elementsPerPage, elementsPerPage); - } - - public static Tutorial create(int creator, String name, String item) { - create.update(creator, name, item); - return by_creator_name.select(creator, name); - } - - public static Tutorial get(int id) { - return by_id.select(id); - } - - @Getter - @Field(keys = {Table.PRIMARY}, autoincrement = true) - private final int tutorialId; - @Getter - @Field(keys = {"CreatorName"}) - private final int creator; - @Getter - @Field(keys = {"CreatorName"}) - private final String name; - @Getter - @Field(def = "'BOOK'") - private final String item; - @Getter - @Field(def = "0") - private final boolean released; - @Getter - @Field(def = "0") // Not really a field, but necessary for select generation - private final double stars; - - public void release() { - release.update(1, tutorialId); - } - - public void delete() { - delete.update(tutorialId); - } - - public void rate(int user, int rating) { - rate.update(tutorialId, user, rating); - } -} diff --git a/TutorialSystem/build.gradle.kts b/TutorialSystem/build.gradle.kts deleted file mode 100644 index 0336de236..000000000 --- a/TutorialSystem/build.gradle.kts +++ /dev/null @@ -1,28 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2024 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 . - */ - -plugins { - steamwar.java -} - -dependencies { - compileOnly(project(":SpigotCore", "default")) - - compileOnly(libs.nms15) -} diff --git a/TutorialSystem/src/de/steamwar/tutorial/TutorialSystem.java b/TutorialSystem/src/de/steamwar/tutorial/TutorialSystem.java deleted file mode 100644 index a261375fa..000000000 --- a/TutorialSystem/src/de/steamwar/tutorial/TutorialSystem.java +++ /dev/null @@ -1,51 +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 . - */ - -package de.steamwar.tutorial; - -import de.steamwar.tutorial.commands.BookReplaceCommand; -import de.steamwar.tutorial.commands.TutorialCommand; -import de.steamwar.tutorial.commands.UnsignCommand; -import de.steamwar.tutorial.listener.Joining; -import de.steamwar.tutorial.listener.RateSign; -import org.bukkit.plugin.java.JavaPlugin; - -public class TutorialSystem extends JavaPlugin { - - private static TutorialSystem plugin; - - @Override - public void onLoad() { - plugin = this; - } - - @Override - public void onEnable() { - new RateSign(); - new Joining(); - - new BookReplaceCommand(); - new TutorialCommand(); - new UnsignCommand(); - } - - public static TutorialSystem getPlugin() { - return plugin; - } -} diff --git a/TutorialSystem/src/de/steamwar/tutorial/commands/BookReplaceCommand.java b/TutorialSystem/src/de/steamwar/tutorial/commands/BookReplaceCommand.java deleted file mode 100644 index 46f6008f1..000000000 --- a/TutorialSystem/src/de/steamwar/tutorial/commands/BookReplaceCommand.java +++ /dev/null @@ -1,48 +0,0 @@ -package de.steamwar.tutorial.commands; - -import de.steamwar.command.SWCommand; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.BookMeta; -import org.bukkit.inventory.meta.ItemMeta; - -import java.util.List; - -public class BookReplaceCommand extends SWCommand { - - public BookReplaceCommand() { - super("bookreplace"); - } - - @Register("color") - public void color(Player player) { - ItemStack itemStack = player.getInventory().getItemInMainHand(); - ItemMeta itemMeta = itemStack.getItemMeta(); - if (itemMeta instanceof BookMeta) { - BookMeta bookMeta = (BookMeta) itemMeta; - replace(bookMeta, '&', '§'); - itemStack.setItemMeta(bookMeta); - player.getInventory().setItemInMainHand(itemStack); - } - } - - @Register("uncolor") - public void uncolor(Player player) { - ItemStack itemStack = player.getInventory().getItemInMainHand(); - ItemMeta itemMeta = itemStack.getItemMeta(); - if (itemMeta instanceof BookMeta) { - BookMeta bookMeta = (BookMeta) itemMeta; - replace(bookMeta, '§', '&'); - itemStack.setItemMeta(bookMeta); - player.getInventory().setItemInMainHand(itemStack); - } - } - - private void replace(BookMeta bookMeta, char oldChar, char newChar) { - List stringList = bookMeta.getPages(); - for (int i = 0; i < stringList.size(); i++) { - String string = stringList.get(i); - bookMeta.setPage(i + 1, string.replace(oldChar, newChar)); - } - } -} diff --git a/TutorialSystem/src/de/steamwar/tutorial/commands/TutorialCommand.java b/TutorialSystem/src/de/steamwar/tutorial/commands/TutorialCommand.java deleted file mode 100644 index f3824d96b..000000000 --- a/TutorialSystem/src/de/steamwar/tutorial/commands/TutorialCommand.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.steamwar.tutorial.commands; - -import de.steamwar.command.SWCommand; -import de.steamwar.network.NetworkSender; -import de.steamwar.network.packets.client.ExecuteCommandPacket; -import de.steamwar.sql.SteamwarUser; -import org.bukkit.entity.Player; - -public class TutorialCommand extends SWCommand { - - public TutorialCommand() { - super("tutorial"); - } - - @Register("rate") - public void rateCommand(Player player) { - rate(player); - } - - public static void rate(Player player) { - NetworkSender.send(new ExecuteCommandPacket(SteamwarUser.get(player.getUniqueId()).getId(), "tutorial rate " + System.getProperty("tutorial"))); - } -} diff --git a/TutorialSystem/src/de/steamwar/tutorial/commands/UnsignCommand.java b/TutorialSystem/src/de/steamwar/tutorial/commands/UnsignCommand.java deleted file mode 100644 index 847db16f2..000000000 --- a/TutorialSystem/src/de/steamwar/tutorial/commands/UnsignCommand.java +++ /dev/null @@ -1,21 +0,0 @@ -package de.steamwar.tutorial.commands; - -import de.steamwar.command.SWCommand; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -public class UnsignCommand extends SWCommand { - - public UnsignCommand() { - super("unsign"); - } - - @Register - public void unsignCommand(Player p) { - ItemStack itemStack = p.getInventory().getItemInMainHand(); - if (itemStack.getType() != Material.WRITTEN_BOOK) return; - itemStack.setType(Material.WRITABLE_BOOK); - p.getInventory().setItemInMainHand(itemStack); - } -} diff --git a/TutorialSystem/src/de/steamwar/tutorial/listener/BasicListener.java b/TutorialSystem/src/de/steamwar/tutorial/listener/BasicListener.java deleted file mode 100644 index 4ef5f8c71..000000000 --- a/TutorialSystem/src/de/steamwar/tutorial/listener/BasicListener.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 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.tutorial.listener; - -import de.steamwar.tutorial.TutorialSystem; -import org.bukkit.Bukkit; -import org.bukkit.event.Listener; - -public abstract class BasicListener implements Listener { - - public BasicListener() { - Bukkit.getPluginManager().registerEvents(this, TutorialSystem.getPlugin()); - } -} diff --git a/TutorialSystem/src/de/steamwar/tutorial/listener/Joining.java b/TutorialSystem/src/de/steamwar/tutorial/listener/Joining.java deleted file mode 100644 index d347a2622..000000000 --- a/TutorialSystem/src/de/steamwar/tutorial/listener/Joining.java +++ /dev/null @@ -1,40 +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 . - */ - -package de.steamwar.tutorial.listener; - -import org.bukkit.Bukkit; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerQuitEvent; - -public class Joining extends BasicListener { - - @EventHandler - public void onJoin(PlayerJoinEvent event) { - event.getPlayer().setOp(true); - } - - @EventHandler - public void onQuit(PlayerQuitEvent event) { - if (Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(event.getPlayer()))) { - Bukkit.shutdown(); - } - } -} diff --git a/TutorialSystem/src/de/steamwar/tutorial/listener/RateSign.java b/TutorialSystem/src/de/steamwar/tutorial/listener/RateSign.java deleted file mode 100644 index 01d87505a..000000000 --- a/TutorialSystem/src/de/steamwar/tutorial/listener/RateSign.java +++ /dev/null @@ -1,48 +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 . - */ - -package de.steamwar.tutorial.listener; - -import de.steamwar.tutorial.commands.TutorialCommand; -import org.bukkit.block.BlockState; -import org.bukkit.block.Sign; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.block.Action; -import org.bukkit.event.player.PlayerInteractEvent; - -public class RateSign extends BasicListener { - - @EventHandler - public void onInteract(PlayerInteractEvent event) { - if(!event.hasBlock() || event.getAction() != Action.RIGHT_CLICK_BLOCK) - return; - - BlockState state = event.getClickedBlock().getState(); - if (!(state instanceof Sign)) - return; - - Sign sign = (Sign) state; - if(!"[rate]".equals(sign.getLine(0))) - return; - - Player player = event.getPlayer(); - TutorialCommand.rate(player); - } -} diff --git a/TutorialSystem/src/plugin.yml b/TutorialSystem/src/plugin.yml deleted file mode 100644 index 8534f043f..000000000 --- a/TutorialSystem/src/plugin.yml +++ /dev/null @@ -1,7 +0,0 @@ -name: TutorialSystem -version: "1.0" -authors: - - Lixfel -main: de.steamwar.tutorial.TutorialSystem -depend: [SpigotCore] -api-version: "1.13" diff --git a/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java b/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java index 566204685..d295d62bc 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java @@ -52,7 +52,6 @@ public class ServerStarter { public static final String TEMP_WORLD_PATH = TMP_DATA + "arenaserver/"; private static final String WORLDS_FOLDER = "/worlds"; - public static final String TUTORIAL_PATH = WORLDS_FOLDER + "/tutorials/"; public static final String WORLDS_BASE_PATH = WORLDS_FOLDER + "/userworlds"; public static final String BUILDER_BASE_PATH = WORLDS_FOLDER + "/builder"; @@ -194,15 +193,6 @@ public class ServerStarter { return this; } - public ServerStarter tutorial(Player owner, Tutorial tutorial) { - version = ServerVersion.SPIGOT_15; - directory = new File(SERVER_PATH, "Tutorial"); - buildWithTemp(owner); - tempWorld(TUTORIAL_PATH + tutorial.getTutorialId()); - arguments.put("tutorial", String.valueOf(tutorial.getTutorialId())); - return send(owner); - } - private void tempWorld(String template) { worldDir = TEMP_WORLD_PATH; worldSetup = () -> copyWorld(node, template, worldDir + worldName); diff --git a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java index 841b657d7..392478b03 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java +++ b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java @@ -215,7 +215,6 @@ public class VelocityCore implements ReloadablePlugin { new ChallengeCommand(); new HistoricCommand(); new ReplayCommand(); - new TutorialCommand(); new Broadcaster(); new CookieEvents(); diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/TutorialCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/TutorialCommand.java deleted file mode 100644 index 877b74790..000000000 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/TutorialCommand.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 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.velocitycore.commands; - -import de.steamwar.command.SWCommand; -import de.steamwar.command.TypeValidator; -import de.steamwar.messages.Chatter; -import de.steamwar.messages.Message; -import de.steamwar.messages.PlayerChatter; -import de.steamwar.persistent.Subserver; -import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.Tutorial; -import de.steamwar.sql.UserPerm; -import de.steamwar.velocitycore.ServerStarter; -import de.steamwar.velocitycore.SubserverSystem; -import de.steamwar.velocitycore.VelocityCore; -import de.steamwar.velocitycore.inventory.SWInventory; -import de.steamwar.velocitycore.inventory.SWItem; -import de.steamwar.velocitycore.inventory.SWListInv; -import de.steamwar.velocitycore.inventory.SWStreamInv; - -import java.io.File; -import java.util.Arrays; -import java.util.concurrent.TimeUnit; - -public class TutorialCommand extends SWCommand { - - public TutorialCommand() { - super("tutorial"); - } - - @Register - public void genericCommand(PlayerChatter sender) { - openInventory(sender, true, false); - } - - @Register("rate") - public void rate(PlayerChatter sender) { - sender.getPlayer().spoofChatInput("/tutorial rate"); - } - - @Register("rate") - public void rate(PlayerChatter sender, int id) { - Tutorial tutorial = Tutorial.get(id); - if(tutorial == null) { - sender.getPlayer().spoofChatInput("/tutorial rate"); // Catch players manually entering numbers - return; - } - - rate(sender, tutorial); - } - - @Register(value = "create", description = "TUTORIAL_CREATE_HELP") - public void create(PlayerChatter sender, String material, String... name) { - create(sender, String.join(" ", name), material.toUpperCase()); - } - - @Register("own") - public void own(PlayerChatter sender) { - openInventory(sender, false, true); - } - - @Register("unreleased") - public void unreleased(@Validator("unreleased") PlayerChatter sender) { - openInventory(sender, false, false); - } - - @Validator("unreleased") - public TypeValidator unreleasedChecker() { - return (sender, value, messageSender) -> sender.user().hasPerm(UserPerm.TEAM); - } - - private void openInventory(PlayerChatter sender, boolean released, boolean own) { - SteamwarUser user = sender.user(); - - new SWStreamInv<>( - sender, - new Message("TUTORIAL_TITLE"), - (click, tutorial) -> { - if(!released && click.isShiftClick() && user.hasPerm(UserPerm.TEAM) && user.getId() != tutorial.getCreator()) { - tutorial.release(); - openInventory(sender, released, own); - return; - } else if(own && click.isShiftClick() && click.isRightClick()) { - tutorial.delete(); - SubserverSystem.deleteFolder(VelocityCore.local, world(tutorial).getPath()); - openInventory(sender, released, own); - return; - } - - new ServerStarter().tutorial(sender.getPlayer(), tutorial).start(); - }, - page -> (own ? Tutorial.getOwn(user.getId(), page, 45) : Tutorial.getPage(page, 45, released)).stream().map(tutorial -> new SWListInv.SWListEntry<>(getTutorialItem(tutorial, own), tutorial)).toList() - ).open(); - } - - private SWItem getTutorialItem(Tutorial tutorial, boolean personalHighlights) { - SWItem item = new SWItem(tutorial.getItem(), new Message("TUTORIAL_NAME", tutorial.getName())); - item.setHideAttributes(true); - - item.addLore(new Message("TUTORIAL_BY", SteamwarUser.get(tutorial.getCreator()).getUserName())); - item.addLore(new Message("TUTORIAL_STARS", String.format("%.1f", tutorial.getStars()))); - - if (personalHighlights) - item.addLore(new Message("TUTORIAL_DELETE")); - - if (personalHighlights && tutorial.isReleased()) - item.setEnchanted(true); - - return item; - } - - private void rate(PlayerChatter sender, Tutorial tutorial) { - int[] rates = new int[]{1, 2, 3, 4, 5}; - - new SWListInv<>(sender, new Message("TUTORIAL_RATE_TITLE"), Arrays.stream(rates).mapToObj(rate -> new SWListInv.SWListEntry<>(new SWItem("NETHER_STAR", new Message("TUTORIAL_RATE", rate)), rate)).toList(), (click, rate) -> { - tutorial.rate(sender.user().getId(), rate); - SWInventory.close(sender); - }).open(); - } - - private void create(PlayerChatter sender, String name, String item) { - Subserver subserver = Subserver.getSubserver(sender.getPlayer()); - SteamwarUser user = sender.user(); - File tempWorld = new File(ServerStarter.TEMP_WORLD_PATH, ServerStarter.serverToWorldName(ServerStarter.bauServerName(user))); - - if(!Subserver.isBuild(subserver) || !subserver.isStarted() || !tempWorld.exists()) { - sender.system("TUTORIAL_CREATE_MISSING"); - return; - } - - subserver.execute("save-all"); - VelocityCore.schedule(() -> { - Tutorial tutorial = Tutorial.create(user.getId(), name, item); - File tutorialWorld = world(tutorial); - - if (tutorialWorld.exists()) - SubserverSystem.deleteFolder(VelocityCore.local, tutorialWorld.getPath()); - ServerStarter.copyWorld(VelocityCore.local, tempWorld.getPath(), tutorialWorld.getPath()); - sender.system("TUTORIAL_CREATED"); - }).delay(1, TimeUnit.SECONDS).schedule(); - } - - private File world(Tutorial tutorial) { - return new File(ServerStarter.TUTORIAL_PATH, String.valueOf(tutorial.getTutorialId())); - } -} From 23df187eb1ecd683bd19f10c53debf12b29755d5 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 30 Jun 2025 15:52:51 +0200 Subject: [PATCH 083/153] settings.gradle.kts aktualisiert --- settings.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 1fe0442bb..f035ee047 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -111,11 +111,11 @@ dependencyResolutionManagement { library("spigotapi", "org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT") library("spigotannotations", "org.spigotmc:plugin-annotations:1.2.3-SNAPSHOT") library("paperapi", "io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT") - library("paperapi21", "io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT") + library("paperapi21", "io.papermc.paper:paper-api:1.21.6-R0.1-SNAPSHOT") library("authlib", "com.mojang:authlib:1.5.25") library("datafixer", "com.mojang:datafixerupper:4.0.26") library("brigadier", "com.mojang:brigadier:1.0.18") - library("anvilgui", "net.wesjd:anvilgui:1.10.5-SNAPSHOT") + library("anvilgui", "net.wesjd:anvilgui:1.10.6-SNAPSHOT") library("nms8", "de.steamwar:spigot:1.8") library("nms9", "de.steamwar:spigot:1.9") From dbd979a5fe5aa32d7680540d2ce68113b17ae87b Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 30 Jun 2025 15:58:31 +0200 Subject: [PATCH 084/153] Fix 1.21 --- VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java b/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java index 4b114a8fb..42c02fe56 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java @@ -44,14 +44,14 @@ public enum ServerVersion { PAPER_18("paper-1.18.2.jar", 15, ProtocolVersion.MINECRAFT_1_18_2), PAPER_19("paper-1.19.3.jar", 19, ProtocolVersion.MINECRAFT_1_19_3), PAPER_20("paper-1.20.1.jar", 20, ProtocolVersion.MINECRAFT_1_20), - PAPER_21("paper-1.21.5.jar", 21, ProtocolVersion.MINECRAFT_1_21_5); + PAPER_21("paper-1.21.6.jar", 21, ProtocolVersion.MINECRAFT_1_21_6); private static final Map chatMap = new HashMap<>(); static { chatMap.put("21", ServerVersion.PAPER_21); chatMap.put("1.21", ServerVersion.PAPER_21); - chatMap.put("1.21.3", ServerVersion.PAPER_21); + chatMap.put("1.21.6", ServerVersion.PAPER_21); chatMap.put("20", ServerVersion.PAPER_20); chatMap.put("1.20", ServerVersion.PAPER_20); From 9798c08cf3f67adf013e7cad7266ac094379a843 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Mon, 30 Jun 2025 16:02:40 +0200 Subject: [PATCH 085/153] Hotfix SmartPlaceListener --- .../features/smartplace/SmartPlaceListener.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java index 17e0d9f35..91c3c6663 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java @@ -61,12 +61,16 @@ public class SmartPlaceListener implements Listener { for (Material material : Material.values()) { if (material.isLegacy()) continue; if (!material.isInteractable() && !material.isBlock()) continue; - BlockData blockData = material.createBlockData(); - block.setBlockData(blockData); - if (block.getState() instanceof TileState) { - CONTAINERS.add(material); - } else if (blockData instanceof Stairs) { - CONTAINERS.add(material); + try { + BlockData blockData = material.createBlockData(); + block.setBlockData(blockData); + if (block.getState() instanceof TileState) { + CONTAINERS.add(material); + } else if (blockData instanceof Stairs) { + CONTAINERS.add(material); + } + } catch (Exception e) { + // Ignore } } CONTAINERS.add(Material.GRINDSTONE); From f37fbfffdf48eaa653174c817471a1264d47aeff Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Mon, 30 Jun 2025 16:05:52 +0200 Subject: [PATCH 086/153] Hotfix SmartPlaceListener --- .../smartplace/SmartPlaceListener.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java index 91c3c6663..d2c8e683b 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java @@ -57,21 +57,19 @@ public class SmartPlaceListener implements Listener { static { World world = Bukkit.getWorlds().get(0); Block block = world.getBlockAt(0, 0, 0); + block.setType(Material.AIR); BlockState state = block.getState(); for (Material material : Material.values()) { if (material.isLegacy()) continue; if (!material.isInteractable() && !material.isBlock()) continue; - try { - BlockData blockData = material.createBlockData(); - block.setBlockData(blockData); - if (block.getState() instanceof TileState) { - CONTAINERS.add(material); - } else if (blockData instanceof Stairs) { - CONTAINERS.add(material); - } - } catch (Exception e) { - // Ignore + BlockData blockData = material.createBlockData(); + block.setBlockData(blockData); + if (block.getState() instanceof TileState) { + CONTAINERS.add(material); + } else if (blockData instanceof Stairs) { + CONTAINERS.add(material); } + state.update(true, false); } CONTAINERS.add(Material.GRINDSTONE); CONTAINERS.remove(Material.COMPARATOR); From e9f8a89758416500624066039ad642b7489c73c0 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Mon, 30 Jun 2025 16:48:03 +0200 Subject: [PATCH 087/153] Hotfix Tablist duplicate names after softreload --- VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java b/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java index 26835f8e2..8c897e25b 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java +++ b/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java @@ -176,6 +176,8 @@ public class Tablist extends ChannelInboundHandlerAdapter { } public void disable() { + sendTabPacket(new ArrayList<>(directTabItems.values()), null); + directTabItems.clear(); sendTabPacket(current, null); current.clear(); From 86537a00deadde7df00f52d2565dec7d61e52ce7 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Mon, 30 Jun 2025 16:52:02 +0200 Subject: [PATCH 088/153] Fix TraceRecorder --- .../steamwar/bausystem/features/tracer/TraceRecorder.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecorder.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecorder.java index 208b49e8a..aef9f12cb 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecorder.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecorder.java @@ -23,6 +23,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.region.Region; import de.steamwar.linkage.Linked; +import de.steamwar.linkage.LinkedInstance; import org.bukkit.Bukkit; import org.bukkit.block.Block; import org.bukkit.entity.TNTPrimed; @@ -31,7 +32,6 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntitySpawnEvent; -import org.bukkit.event.server.PluginEnableEvent; import java.util.*; import java.util.logging.Level; @@ -40,12 +40,9 @@ import java.util.logging.Logger; @Linked public class TraceRecorder implements Listener { + @LinkedInstance public static TraceRecorder instance; - { - instance = this; - } - /** * Map for all traces being actively recorded */ From 8ff0319fe69f49206530adfe81d66df9cac9cc08 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Mon, 30 Jun 2025 16:53:28 +0200 Subject: [PATCH 089/153] Fix BauSystem.properties --- BauSystem/BauSystem_Main/src/BauSystem.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem/BauSystem_Main/src/BauSystem.properties b/BauSystem/BauSystem_Main/src/BauSystem.properties index 2a829ec15..e1cce9bff 100644 --- a/BauSystem/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem/BauSystem_Main/src/BauSystem.properties @@ -515,7 +515,7 @@ LOADER_HELP_GUI=§8/§7loader gui §8- §7Shows Loader gui LOADER_HELP_STOP=§8/§eloader stop §8- §7Stops recording/playback LOADER_HELP_WAIT=§8/§7loader wait §8[§7Ticks§8] - §7Sets wait time between shots LOADER_HELP_SPEED=§8/§7loader speed §8[§7Ticks§8] - §7Sets wait time between actions -LOADER_NO_LOADER=§cYou have no Laoder. Create one with /loader setup +LOADER_NO_LOADER=§cYou have no Loader. Create one with /loader setup LOADER_NEW=§7Load your cannon and fire it once, to initialise the loader. LOADER_HOW_TO_START=§7Then, execute /§eloader start§7 to start the Loader LOADER_ACTIVE=§7The Loader is now active. From 4fc707431fce5956a5d37e5f9115227a277d06fe Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Mon, 30 Jun 2025 17:10:24 +0200 Subject: [PATCH 090/153] Fix WorldEditRenderer --- .../src/de/steamwar/core/WorldEditRenderer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java index 5e3595121..225053a23 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java @@ -95,8 +95,8 @@ public class WorldEditRenderer implements Listener { WorldEditRendererWrapper.impl.hide(owner, true, true); WorldEditRendererWrapper.impl.hide(owner, false, true); } else { - WorldEditRendererWrapper.impl.hide(owner, true, false); - WorldEditRendererWrapper.impl.hide(owner, false, false); + WorldEditRendererWrapper.impl.hide(owner, true, WorldEditRendererCUIEditor.Type.CLIPBOARD.getMaterial(owner) == Material.BARRIER); + WorldEditRendererWrapper.impl.hide(owner, false, WorldEditRendererCUIEditor.Type.SELECTION.getMaterial(owner) == Material.BARRIER); WorldEditRendererWrapper.safeDraw(owner, scheduled, clipboard, min, max); } } From 9988774fb4d309b7a03f28240ca1d76b4dd006a2 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Mon, 30 Jun 2025 17:27:23 +0200 Subject: [PATCH 091/153] Fix Warp.WorldSpawn --- .../src/de/steamwar/bausystem/features/warp/Warp.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/warp/Warp.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/warp/Warp.java index 4ccddf765..a13929170 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/warp/Warp.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/warp/Warp.java @@ -36,7 +36,7 @@ public class Warp { 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.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); } From 617bae5a5cb8db3acc1313642eba47aaa10ab72f Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Tue, 1 Jul 2025 18:48:59 +0200 Subject: [PATCH 092/153] Add AuditLog --- .../SQL/src/de/steamwar/sql/AuditLog.java | 132 ++++++++++++++++++ .../de/steamwar/fightsystem/FightSystem.java | 5 + .../src/de/steamwar/bausystem/BauSystem.java | 1 + .../src/de/steamwar/lobby/LobbySystem.java | 2 + .../CaseInsensitiveCommandsListener.java | 5 + .../src/de/steamwar/core/Core.java | 18 ++- .../core/events/PlayerJoinedEvent.java | 7 +- .../de/steamwar/inventory/SWInventory.java | 10 +- .../de/steamwar/providers/BauServerInfo.java | 6 + .../steamwar/velocitycore/ServerStarter.java | 1 + .../velocitycore/listeners/ChatListener.java | 32 ++++- .../listeners/SessionManager.java | 3 + 12 files changed, 210 insertions(+), 12 deletions(-) create mode 100644 CommonCore/SQL/src/de/steamwar/sql/AuditLog.java diff --git a/CommonCore/SQL/src/de/steamwar/sql/AuditLog.java b/CommonCore/SQL/src/de/steamwar/sql/AuditLog.java new file mode 100644 index 000000000..82d07c1b9 --- /dev/null +++ b/CommonCore/SQL/src/de/steamwar/sql/AuditLog.java @@ -0,0 +1,132 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.sql; + +import de.steamwar.sql.internal.*; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NonNull; + +import java.sql.Timestamp; +import java.time.Instant; + +@AllArgsConstructor +public class AuditLog { + + static { + SqlTypeMapper.nameEnumMapper(AuditLog.Type.class); + } + + public static final String SERVER_NAME_VELOCITY = "Velocity"; + + private static final Table table = new Table<>(AuditLog.class); + + private static final SelectStatement byId = table.select(Table.PRIMARY); + + private static final Statement create = table.insertFields(true, "time", "serverName", "serverOwner", "actor", "actionType", "actionText"); + + @Getter + @Field(keys = {Table.PRIMARY}, autoincrement = true) + private final int auditLogId; + + @Getter + @Field + private final Timestamp time; + + @Getter + @Field + private final String serverName; + + @Field(nullable = true) + private final int serverOwner; + + @Field + private final int actor; + + @Getter + @Field + private final Type actionType; + + @Getter + @Field + private final String actionText; + + public enum Type { + JOIN, + LEAVE, + COMMAND, + SENSITIVE_COMMAND, + + CHAT, + GUI_OPEN, + GUI_CLOSE, + GUI_CLICK, + } + + public static AuditLog get(int auditLogId) { + return byId.select(auditLogId); + } + + private static AuditLog create(String serverName, SteamwarUser serverOwner, SteamwarUser actor, Type actionType, String text) { + return get(create.insertGetKey(Timestamp.from(Instant.now()), serverName, serverOwner, actor, actionType, text)); + } + + public static AuditLog createJoin(@NonNull String jointServerName, SteamwarUser serverOwner, @NonNull SteamwarUser joinedPlayer) { + return create(jointServerName, serverOwner, joinedPlayer, Type.JOIN, ""); + } + + public static AuditLog createLeave(@NonNull String leftServerName, SteamwarUser serverOwner, @NonNull SteamwarUser joinedPlayer) { + return create(leftServerName, serverOwner, joinedPlayer, Type.LEAVE, ""); + } + + public static AuditLog createCommand(@NonNull String serverName, SteamwarUser serverOwner, SteamwarUser player, @NonNull String command) { + if (player == null) return null; + return create(serverName, serverOwner, player, Type.COMMAND, command); + } + + public static AuditLog createSensitiveCommand(@NonNull String serverName, SteamwarUser serverOwner, SteamwarUser player, @NonNull String command) { + if (player == null) return null; + return create(serverName, serverOwner, player, Type.SENSITIVE_COMMAND, command); + } + + public static AuditLog createChat(@NonNull String serverName, SteamwarUser serverOwner, @NonNull SteamwarUser chatter, @NonNull String chat) { + return create(serverName, serverOwner, chatter, Type.CHAT, chat); + } + + public static AuditLog createGuiOpen(@NonNull String serverName, SteamwarUser serverOwner, @NonNull SteamwarUser player, @NonNull String guiName) { + return create(serverName, serverOwner, player, Type.GUI_OPEN, guiName); + } + + public static AuditLog createGuiClick(@NonNull String serverName, SteamwarUser serverOwner, @NonNull SteamwarUser player, @NonNull String guiName, @NonNull String clickType, int slot, @NonNull String itemName) { + return create(serverName, serverOwner, player, Type.GUI_CLICK, "Gui: " + guiName + "\nSlot: " + slot + "\nClickType: " + clickType + "\nItemName: " + itemName); + } + + public static AuditLog createGuiClose(@NonNull String serverName, SteamwarUser serverOwner, @NonNull SteamwarUser player, @NonNull String guiName) { + return create(serverName, serverOwner, player, Type.GUI_CLOSE, guiName); + } + + public SteamwarUser getServerOwner() { + return SteamwarUser.get(serverOwner); + } + + public SteamwarUser getActor() { + return SteamwarUser.get(actor); + } +} diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 9ebc4f0c9..67a6116e2 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -68,6 +68,11 @@ public class FightSystem extends JavaPlugin { Core.setInstance(this); TinyProtocol.init(); } + if (Config.SpectatePort != 0) { + Core.setServerName("Spectate"); + } else if (Config.ReplayID != 0) { + Core.setServerName("Replay"); + } message = new Message("de.steamwar.fightsystem.FightSystem", FightSystem.class.getClassLoader()); diff --git a/LegacyBauSystem/src/de/steamwar/bausystem/BauSystem.java b/LegacyBauSystem/src/de/steamwar/bausystem/BauSystem.java index 56af8fd7a..6712e45a5 100644 --- a/LegacyBauSystem/src/de/steamwar/bausystem/BauSystem.java +++ b/LegacyBauSystem/src/de/steamwar/bausystem/BauSystem.java @@ -53,6 +53,7 @@ public class BauSystem extends JavaPlugin implements Listener { @Override public void onEnable() { + Core.setServerName("Dev"); plugin = this; Mapper.init(); diff --git a/LobbySystem/src/de/steamwar/lobby/LobbySystem.java b/LobbySystem/src/de/steamwar/lobby/LobbySystem.java index 4d198d4b7..900d09410 100644 --- a/LobbySystem/src/de/steamwar/lobby/LobbySystem.java +++ b/LobbySystem/src/de/steamwar/lobby/LobbySystem.java @@ -19,6 +19,7 @@ package de.steamwar.lobby; +import de.steamwar.core.Core; import de.steamwar.entity.REntityServer; import de.steamwar.lobby.command.FlyCommand; import de.steamwar.lobby.command.HologramCommand; @@ -52,6 +53,7 @@ public class LobbySystem extends JavaPlugin { message = new Message("de.steamwar.lobby.LobbySystem", getClassLoader()); entityServer = new REntityServer(); debugEntityServer = new REntityServer(); + Core.setServerName("Lobby"); CustomMap.init(); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/command/CaseInsensitiveCommandsListener.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/command/CaseInsensitiveCommandsListener.java index a829308a1..05eafdbbd 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/command/CaseInsensitiveCommandsListener.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/command/CaseInsensitiveCommandsListener.java @@ -19,6 +19,10 @@ package de.steamwar.command; +import de.steamwar.core.Core; +import de.steamwar.providers.BauServerInfo; +import de.steamwar.sql.AuditLog; +import de.steamwar.sql.SteamwarUser; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -31,5 +35,6 @@ public class CaseInsensitiveCommandsListener implements Listener { String[] strings = event.getMessage().split(" "); strings[0] = strings[0].toLowerCase(); event.setMessage(String.join(" ", strings)); + AuditLog.createCommand(Core.getServerName(), BauServerInfo.getOwnerUser(), SteamwarUser.get(event.getPlayer().getUniqueId()), event.getMessage()); } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java index c2086b0b6..91c05851f 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -33,6 +33,8 @@ import de.steamwar.network.handlers.ServerDataHandler; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.internal.Statement; +import lombok.Getter; +import lombok.Setter; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.event.Listener; @@ -52,12 +54,17 @@ public class Core extends JavaPlugin { return Reflection.MAJOR_VERSION; } + @Getter + @Setter private static JavaPlugin instance; - public static JavaPlugin getInstance() { - return instance; - } - public static void setInstance(JavaPlugin instance) { - Core.instance = instance; + + @Getter + private static String serverName = ""; + + public static void setServerName(String serverName) { + if (serverName.isEmpty()) { + Core.serverName = serverName; + } } private ErrorHandler errorHandler; @@ -66,6 +73,7 @@ public class Core extends JavaPlugin { @Override public void onLoad() { setInstance(this); + serverName = System.getProperty("serverName", ""); } @Override diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java index 29b0ffd8d..d3fd33a06 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java @@ -19,6 +19,9 @@ package de.steamwar.core.events; +import de.steamwar.core.Core; +import de.steamwar.providers.BauServerInfo; +import de.steamwar.sql.AuditLog; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserPerm; import de.steamwar.sql.internal.Statement; @@ -44,12 +47,14 @@ public class PlayerJoinedEvent implements Listener{ player.setDisplayName(prefix.getColorCode() + player.getName() + "§r"); event.setJoinMessage("§a§l» §r" + player.getDisplayName()); + AuditLog.createJoin(Core.getServerName(), BauServerInfo.getOwnerUser(), user); } - @EventHandler + @EventHandler(priority = EventPriority.LOWEST) private void onQuit(PlayerQuitEvent event) { Player player = event.getPlayer(); event.setQuitMessage("§c§l« §r" + player.getDisplayName()); + AuditLog.createLeave(Core.getServerName(), BauServerInfo.getOwnerUser(), SteamwarUser.get(player.getUniqueId())); } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWInventory.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWInventory.java index 001fae9f2..1b4529d31 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWInventory.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWInventory.java @@ -20,7 +20,9 @@ package de.steamwar.inventory; import de.steamwar.core.Core; -import de.steamwar.core.TrickyTrialsWrapper; +import de.steamwar.providers.BauServerInfo; +import de.steamwar.sql.AuditLog; +import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -145,6 +147,7 @@ public class SWInventory implements Listener { Bukkit.getPluginManager().registerEvents(this, Core.getInstance()); open = true; } + AuditLog.createGuiOpen(Core.getServerName(), BauServerInfo.getOwnerUser(), SteamwarUser.get(player.getUniqueId()), title); } @EventHandler @@ -156,6 +159,7 @@ public class SWInventory implements Listener { e.setCancelled(true); Core.getInstance().getLogger().info("[SWINV] " + e.getWhoClicked().getName() + " " + e.getClick().name() + " clicked " + e.getRawSlot() + " on " + (e.getCurrentItem() != null ? e.getCurrentItem().getItemMeta().getDisplayName() : "[EMPTY]") + " in " + e.getView().getTitle()); callbacks.get(e.getRawSlot()).accept(e); + AuditLog.createGuiClick(Core.getServerName(), BauServerInfo.getOwnerUser(), SteamwarUser.get(player.getUniqueId()), e.getView().getTitle(), e.getClick().name(), e.getRawSlot(), (e.getCurrentItem() != null ? e.getCurrentItem().getItemMeta().getDisplayName() : "[EMPTY]")); } } @@ -167,8 +171,10 @@ public class SWInventory implements Listener { InventoryClickEvent.getHandlerList().unregister(this); InventoryCloseEvent.getHandlerList().unregister(this); Core.getInstance().getLogger().info("[SWINV] " + player.getName() + " closed " + title); - if(callbacks.containsKey(-1)) + if(callbacks.containsKey(-1)) { callbacks.get(-1).accept(null); + } open = false; + AuditLog.createGuiClose(Core.getServerName(), BauServerInfo.getOwnerUser(), SteamwarUser.get(player.getUniqueId()), title); } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/providers/BauServerInfo.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/providers/BauServerInfo.java index ddc7839e5..309db8354 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/providers/BauServerInfo.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/providers/BauServerInfo.java @@ -19,6 +19,7 @@ package de.steamwar.providers; +import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; public class BauServerInfo { @@ -37,4 +38,9 @@ public class BauServerInfo { public static boolean isBauServer() { return bauOwner != null; } + + public static SteamwarUser getOwnerUser() { + if (bauOwner == null) return null; + return SteamwarUser.get(bauOwner); + } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java b/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java index d295d62bc..058771e73 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java @@ -276,6 +276,7 @@ public class ServerStarter { int port = portrange.freePort(); String serverName = serverNameProvider.apply(port); + arguments.put("serverName", serverName); if(node == null) { node = Node.getNode(); diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/ChatListener.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/ChatListener.java index 17137bf5d..dfdf5c7f2 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/ChatListener.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/ChatListener.java @@ -27,6 +27,8 @@ import com.velocitypowered.api.event.player.PlayerChatEvent; import com.velocitypowered.api.event.player.TabCompleteEvent; import com.velocitypowered.api.proxy.ConsoleCommandSource; import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.ServerConnection; +import com.velocitypowered.api.proxy.server.ServerInfo; import de.steamwar.messages.Chatter; import de.steamwar.messages.ChatterGroup; import de.steamwar.messages.Message; @@ -80,17 +82,32 @@ public class ChatListener extends BasicListener { if(VelocityCore.getProxy().getCommandManager().hasCommand(cmd)) { CommandSource source = e.getCommandSource(); String name; - if(source instanceof Player player) + SteamwarUser user = null; + if (source instanceof Player player) { + user = SteamwarUser.get(player.getUniqueId()); name = player.getUsername(); - else if(source instanceof ConsoleCommandSource) + } else if (source instanceof ConsoleCommandSource) { + user = SteamwarUser.get(-1); name = "«CONSOLE»"; - else + } else { name = source.toString(); + } if (noLogCommands.contains(cmd)) { return; } + switch (cmd) { + case "msg": + case "r": + case "tc": + AuditLog.createSensitiveCommand(AuditLog.SERVER_NAME_VELOCITY, null, user, "/" + command); + break; + default: + AuditLog.createCommand(AuditLog.SERVER_NAME_VELOCITY, null, user, "/" + command); + break; + } + cmdLogger.log(Level.INFO, "%s -> executed command /%s".formatted(name, command)); } else if (e.getCommandSource() instanceof Player player) { // System.out.println("spoofChatInput " + e); @@ -106,8 +123,8 @@ public class ChatListener extends BasicListener { e.setResult(PlayerChatEvent.ChatResult.denied()); + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); if (message.contains("jndi:ldap")) { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); PunishmentCommand.ban(user, Punishment.PERMA_TIME, "Versuchte Exploit-Ausnutzung", SteamwarUser.get(-1), true); VelocityCore.getLogger().log(Level.SEVERE, "%s %s wurde automatisch wegen jndi:ldap gebannt.".formatted(user.getUserName(), user.getId())); return; @@ -117,13 +134,20 @@ public class ChatListener extends BasicListener { return; Subserver subserver = Subserver.getSubserver(player); + String serverName = AuditLog.SERVER_NAME_VELOCITY; if(Subserver.isArena(subserver) && subserver.getServer() == player.getCurrentServer().orElseThrow().getServerInfo()) { + serverName = subserver.getServer().getName(); localChat(Chatter.of(player), message); } else if (message.startsWith("+")) { + serverName = player.getCurrentServer() + .map(ServerConnection::getServerInfo) + .map(ServerInfo::getName) + .orElse(serverName); localChat(Chatter.of(player), message.substring(1)); } else { sendChat(Chatter.of(player), Chatter.globalChat(), "CHAT_GLOBAL", null, message); } + AuditLog.createChat(serverName, null, user, message); } private static boolean isMistypedCommand(Player player, String message) { diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/SessionManager.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/SessionManager.java index 7caeac141..248fd6068 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/SessionManager.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/SessionManager.java @@ -22,6 +22,7 @@ package de.steamwar.velocitycore.listeners; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.connection.DisconnectEvent; import com.velocitypowered.api.event.connection.PostLoginEvent; +import de.steamwar.sql.AuditLog; import de.steamwar.velocitycore.VelocityCore; import de.steamwar.sql.Session; import de.steamwar.sql.SteamwarUser; @@ -36,10 +37,12 @@ public class SessionManager extends BasicListener { @Subscribe public void onPostLogin(PostLoginEvent event){ sessions.put(event.getPlayer(), Timestamp.from(Instant.now())); + AuditLog.createJoin(AuditLog.SERVER_NAME_VELOCITY, null, SteamwarUser.get(event.getPlayer().getUniqueId())); } @Subscribe public void onDisconnect(DisconnectEvent e){ + AuditLog.createLeave(AuditLog.SERVER_NAME_VELOCITY, null, SteamwarUser.get(e.getPlayer().getUniqueId())); Timestamp timestamp = sessions.remove(e.getPlayer()); if(timestamp != null) { VelocityCore.schedule(() -> Session.insertSession(SteamwarUser.get(e.getPlayer().getUniqueId()).getId(), timestamp)).schedule(); From 6b16bbc785152140fdf612b67aaacf0bf39e9e03 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Tue, 1 Jul 2025 19:00:14 +0200 Subject: [PATCH 093/153] Add DiscordDependency plugin for faster upload times --- .../DiscordDependency/build.gradle.kts | 36 +++++++++++++++++++ .../src/de/steamwar/discord/Discord.java | 29 +++++++++++++++ VelocityCore/build.gradle.kts | 5 +-- .../steamwar/velocitycore/VelocityCore.java | 2 +- settings.gradle.kts | 1 + steamwarci.yml | 1 + 6 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 VelocityCore/DiscordDependency/build.gradle.kts create mode 100644 VelocityCore/DiscordDependency/src/de/steamwar/discord/Discord.java diff --git a/VelocityCore/DiscordDependency/build.gradle.kts b/VelocityCore/DiscordDependency/build.gradle.kts new file mode 100644 index 000000000..5c4c27a6b --- /dev/null +++ b/VelocityCore/DiscordDependency/build.gradle.kts @@ -0,0 +1,36 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 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 . + */ + +plugins { + steamwar.java +} + +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} + +dependencies { + compileOnly(libs.velocity) + annotationProcessor(libs.velocityapi) + + implementation(libs.jda) { + exclude(module = "opus-java") + } +} \ No newline at end of file diff --git a/VelocityCore/DiscordDependency/src/de/steamwar/discord/Discord.java b/VelocityCore/DiscordDependency/src/de/steamwar/discord/Discord.java new file mode 100644 index 000000000..e45486976 --- /dev/null +++ b/VelocityCore/DiscordDependency/src/de/steamwar/discord/Discord.java @@ -0,0 +1,29 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.discord; + +import com.velocitypowered.api.plugin.Plugin; + +@Plugin( + id = "discordvelocitycore", + name = "DiscordVelocityCore" +) +public class Discord { +} diff --git a/VelocityCore/build.gradle.kts b/VelocityCore/build.gradle.kts index f81416a35..54b55e9c1 100644 --- a/VelocityCore/build.gradle.kts +++ b/VelocityCore/build.gradle.kts @@ -51,6 +51,7 @@ dependencies { compileOnly(libs.viavelocity) compileOnly(project(":VelocityCore:Persistent", "default")) + compileOnly(project(":VelocityCore:DiscordDependency", "default")) implementation(project(":CommonCore")) implementation(project(":CommandFramework")) @@ -58,10 +59,6 @@ dependencies { implementation(libs.sqlite) implementation(libs.mysql) - implementation(libs.jda) { - exclude(module = "opus-java") - } - implementation(libs.msgpack) implementation(libs.apolloprotos) diff --git a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java index 392478b03..22b64f645 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java +++ b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java @@ -60,7 +60,7 @@ import java.util.logging.Logger; @Plugin( id = "velocitycore", name = "VelocityCore", - dependencies = { @Dependency(id = "persistentvelocitycore") } + dependencies = { @Dependency(id = "persistentvelocitycore"), @Dependency(id = "discordvelocitycore") } ) public class VelocityCore implements ReloadablePlugin { diff --git a/settings.gradle.kts b/settings.gradle.kts index 9b530499e..cb1758820 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -247,6 +247,7 @@ include("TutorialSystem") include( "VelocityCore", + "VelocityCore:DiscordDependency", "VelocityCore:Persistent" ) diff --git a/steamwarci.yml b/steamwarci.yml index 3e3660b1d..d62f6b621 100644 --- a/steamwarci.yml +++ b/steamwarci.yml @@ -29,6 +29,7 @@ artifacts: "/jars/TutorialSystem.jar": "TutorialSystem/build/libs/TutorialSystem.jar" "/jars/PersistentVelocityCore.jar": "VelocityCore/Persistent/build/libs/Persistent.jar" + "/jars/DiscordVelocityCore.jar": "VelocityCore/DiscordDependency/build/libs/DiscordDependency.jar" "/jars/VelocityCore.jar": "VelocityCore/build/libs/VelocityCore-all.jar" "/usr/local/bin/deployarena.py": "VelocityCore/deployarena.py" From 8677d59cce95a99613c609b3f307ff0cbc60804a Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Tue, 1 Jul 2025 19:04:13 +0200 Subject: [PATCH 094/153] Fix some stuff --- VelocityCore/DiscordDependency/build.gradle.kts | 1 + VelocityCore/build.gradle.kts | 1 + 2 files changed, 2 insertions(+) diff --git a/VelocityCore/DiscordDependency/build.gradle.kts b/VelocityCore/DiscordDependency/build.gradle.kts index 5c4c27a6b..dbe2ac56e 100644 --- a/VelocityCore/DiscordDependency/build.gradle.kts +++ b/VelocityCore/DiscordDependency/build.gradle.kts @@ -19,6 +19,7 @@ plugins { steamwar.java + alias(libs.plugins.shadow) } java { diff --git a/VelocityCore/build.gradle.kts b/VelocityCore/build.gradle.kts index 54b55e9c1..5074c280c 100644 --- a/VelocityCore/build.gradle.kts +++ b/VelocityCore/build.gradle.kts @@ -70,5 +70,6 @@ tasks.register("DevVelocity") { description = "Run a Dev Velocity" dependsOn(":VelocityCore:shadowJar") dependsOn(":VelocityCore:Persistent:jar") + dependsOn(":VelocityCore:DiscordDependency:jar") template = "DevVelocity" } From bc00873314fc2e952d53e1d509ae0a86f6abc4ce Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Tue, 1 Jul 2025 21:28:59 +0200 Subject: [PATCH 095/153] Update UserPerm --- CommonCore/SQL/src/de/steamwar/sql/UserPerm.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java b/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java index ed842d546..72aebd3a1 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java +++ b/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java @@ -55,11 +55,11 @@ public enum UserPerm { p.put(PREFIX_YOUTUBER, new Prefix("§7", "YT")); p.put(PREFIX_GUIDE, new Prefix("§a", "Guide")); - p.put(PREFIX_SUPPORTER, new Prefix("§6", "Sup")); - p.put(PREFIX_MODERATOR, new Prefix("§6", "Mod")); - p.put(PREFIX_BUILDER, new Prefix("§e", "Arch")); - p.put(PREFIX_DEVELOPER, new Prefix("§e", "Dev")); - p.put(PREFIX_ADMIN, new Prefix("§e", "Admin")); + p.put(PREFIX_SUPPORTER, new Prefix("§x§1§e§3§a§8§a", "Sup")); // #1e3a8a + p.put(PREFIX_MODERATOR, new Prefix("§x§9§2§4§0§0§e", "Mod")); // #92400e + p.put(PREFIX_BUILDER, new Prefix("§x§1§5§8§0§3§d", "Arch")); // #15803d + p.put(PREFIX_DEVELOPER, new Prefix("§x§0§7§5§9§8§5", "Dev")); // #075985 + p.put(PREFIX_ADMIN, new Prefix("§x§9§9§1§b§1§b", "Admin")); // #991b1b prefixes = Collections.unmodifiableMap(p); } From 4ed6bc52d063bf16edc13aa488dc4f8fa3fe71fe Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Tue, 1 Jul 2025 21:37:12 +0200 Subject: [PATCH 096/153] Update TheBreadBeards Easter particle --- .../lobby/particle/elements/None.java | 30 +++++++++++++++++++ .../custom/CustomEasterParticle.java | 19 +++++++----- 2 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 LobbySystem/src/de/steamwar/lobby/particle/elements/None.java diff --git a/LobbySystem/src/de/steamwar/lobby/particle/elements/None.java b/LobbySystem/src/de/steamwar/lobby/particle/elements/None.java new file mode 100644 index 000000000..42bb013d9 --- /dev/null +++ b/LobbySystem/src/de/steamwar/lobby/particle/elements/None.java @@ -0,0 +1,30 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.lobby.particle.elements; + +import de.steamwar.lobby.particle.ParticleElement; +import de.steamwar.lobby.particle.ParticleTickData; + +public class None implements ParticleElement { + + @Override + public void tick(ParticleTickData particleTickData) { + } +} diff --git a/LobbySystem/src/de/steamwar/lobby/particle/particles/custom/CustomEasterParticle.java b/LobbySystem/src/de/steamwar/lobby/particle/particles/custom/CustomEasterParticle.java index 3c8d43c5c..da2070819 100644 --- a/LobbySystem/src/de/steamwar/lobby/particle/particles/custom/CustomEasterParticle.java +++ b/LobbySystem/src/de/steamwar/lobby/particle/particles/custom/CustomEasterParticle.java @@ -78,14 +78,17 @@ public enum CustomEasterParticle implements ParticleEnum { // TODO: Implement TheReaper22122! // TODO: Implement Bosslar! // TODO: Implement ATOM65! - PLAYER_3266(new ParticleData(Material.CHORUS_FRUIT, "PARTICLE_PLAYER_3266", ParticleRequirement.easterEventSpecificPlayer(3266), - new Always(new NonFlying(new Cloud(new LocationMutator(new TrippleCircle( - new DustParticle(Particle.REDSTONE, new Gradient(Color.CYAN, Color.BLUE, Color.MAGENTA.darker(), Color.RED, Color.YELLOW, Color.GREEN, Color.CYAN)), - new DustParticle(Particle.REDSTONE, new Gradient(Color.CYAN, Color.BLUE, Color.MAGENTA.darker(), Color.RED, Color.YELLOW, Color.GREEN, Color.CYAN)), - new DustParticle(Particle.REDSTONE, new Gradient(Color.CYAN, Color.BLUE, Color.MAGENTA.darker(), Color.RED, Color.YELLOW, Color.GREEN, Color.CYAN)), - 0.7, - 0.5), location -> location.add(0, 0.6, 0) - ))))) + PLAYER_3266(new ParticleData(Material.BREAD, "PARTICLE_PLAYER_3266", ParticleRequirement.easterEventSpecificPlayer(3266), + new Group( + new Always(new Sneaking(new LocationMutator(new None(), location -> location))), + new Always(new NonFlying(new LocationMutator(new TrippleCircle( + new DustParticle(Particle.REDSTONE, new Gradient(Color.CYAN, Color.BLUE, Color.MAGENTA.darker(), Color.RED, Color.YELLOW, Color.GREEN, Color.CYAN)), + new DustParticle(Particle.REDSTONE, new Gradient(Color.CYAN, Color.BLUE, Color.MAGENTA.darker(), Color.RED, Color.YELLOW, Color.GREEN, Color.CYAN)), + new DustParticle(Particle.REDSTONE, new Gradient(Color.CYAN, Color.BLUE, Color.MAGENTA.darker(), Color.RED, Color.YELLOW, Color.GREEN, Color.CYAN)), + 0.7, + 0.5), location -> location.add(0, 0.6, 0) + )))) + ) ), // TODO: Implement Gehfxhler! // TODO: Implement SchwarzerFuerst From 4c98ce4aff4d84c602e17d692634616d916f76de Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 1 Jul 2025 21:39:08 +0200 Subject: [PATCH 097/153] Add Schematic Revisions --- .../features/world/ClipboardListener.java | 4 +- .../SQL/src/de/steamwar/sql/NodeData.java | 56 ++++++++++++++----- .../src/de/steamwar/sql/SchematicNode.java | 2 +- .../fightsystem/utils/WorldeditWrapper14.java | 2 +- .../fightsystem/utils/WorldeditWrapper8.java | 2 +- .../fightsystem/listener/PrepareSchem.java | 23 +------- .../steamwar/fightsystem/record/Recorder.java | 2 +- .../bausystem/world/ClipboardListener.java | 2 +- .../src/SchematicSystem.properties | 13 ++++- .../src/SchematicSystem_de.properties | 11 +++- .../commands/DownloadCommand.java | 2 +- .../commands/schematiccommand/GUI.java | 25 ++++++++- .../SchematicCommandUtils.java | 11 +++- .../schematiccommand/parts/SavePart.java | 11 ++-- .../schematiccommand/parts/ViewPart.java | 37 ++++++++++-- .../src/de/steamwar/sql/SchematicData.java | 24 ++++++-- .../discord/listeners/DiscordSchemUpload.java | 2 +- .../src/de/steamwar/routes/Schematic.kt | 5 +- 18 files changed, 165 insertions(+), 69 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/ClipboardListener.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/ClipboardListener.java index 90cd94ec7..2cb2cc7b8 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/ClipboardListener.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/ClipboardListener.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.world; import de.steamwar.bausystem.Permission; import de.steamwar.linkage.Linked; +import de.steamwar.sql.NodeData; import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; @@ -65,7 +66,8 @@ public class ClipboardListener implements Listener { } try { - new SchematicData(schematic).saveFromPlayer(e.getPlayer()); + NodeData.get(schematic).forEach(NodeData::delete); + SchematicData.saveFromPlayer(e.getPlayer(), schematic); } catch (Exception ex) { if (newSchem) { schematic.delete(); diff --git a/CommonCore/SQL/src/de/steamwar/sql/NodeData.java b/CommonCore/SQL/src/de/steamwar/sql/NodeData.java index 08179979f..cc6f0cc93 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/NodeData.java +++ b/CommonCore/SQL/src/de/steamwar/sql/NodeData.java @@ -23,8 +23,13 @@ import de.steamwar.sql.internal.*; import lombok.AllArgsConstructor; import lombok.Getter; +import javax.swing.plaf.nimbus.State; import java.io.*; import java.sql.PreparedStatement; +import java.sql.Timestamp; +import java.time.Instant; +import java.util.List; +import java.util.Optional; import java.util.zip.GZIPInputStream; @AllArgsConstructor @@ -40,26 +45,47 @@ public class NodeData { private static final Table table = new Table<>(NodeData.class); - private static final Statement updateDatabase = new Statement("INSERT INTO NodeData(NodeId, NodeFormat, SchemData) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE NodeFormat = VALUES(NodeFormat), SchemData = VALUES(SchemData)"); - private static final Statement selSchemData = new Statement("SELECT SchemData FROM NodeData WHERE NodeId = ?"); + private static final Statement updateDatabase = new Statement("INSERT INTO NodeData(NodeId, NodeFormat, SchemData) VALUES (?, ?, ?)", true); + private static final Statement selSchemData = new Statement("SELECT SchemData FROM NodeData WHERE NodeId = ? AND CreatedAt = ?"); + private static final Statement delete = table.delete(Table.PRIMARY); - private static final SelectStatement get = table.select(Table.PRIMARY); + private static final SelectStatement get = new SelectStatement<>(table, "SELECT NodeId, CreatedAt, NodeFormat FROM NodeData WHERE NodeId = ? ORDER BY CreatedAt "); + private static final Statement getRevisions = new Statement("SELECT COUNT(DISTINCT CreatedAt) as CNT FROM NodeData WHERE NodeId = ?"); + private static final SelectStatement getLatest = new SelectStatement<>(table, "SELECT NodeId, CreatedAt, NodeFormat FROM NodeData WHERE NodeId = ? ORDER BY CreatedAt LIMIT 1"); - public static NodeData get(SchematicNode node) { - if(node.isDir()) - throw new IllegalArgumentException("Node is a directory"); - return get.select(rs -> { - if(rs.next()) { - return new NodeData(node.getId(), SchematicFormat.values()[rs.getInt("NodeFormat")]); + public static NodeData getLatest(SchematicNode node) { + if (node.isDir()) throw new IllegalArgumentException("Node is dir"); + return Optional.ofNullable(getLatest.select(node)).orElseGet(() -> new NodeData(node.getId(), Timestamp.from(Instant.now()), SchematicFormat.MCEDIT)); + } + + public static List get(SchematicNode node) { + return get.listSelect(node); + } + + public static NodeData get(SchematicNode node, int revision) { + return get.listSelect(node).get(revision - 1); + } + + public static int getRevisions(SchematicNode node) { + return getRevisions.select(rs -> { + if (rs.next()) { + return rs.getInt("CNT"); } else { - return new NodeData(node.getId(), SchematicFormat.MCEDIT); + return 0; } }, node); } + public static void saveFromStream(SchematicNode node, InputStream blob, SchematicFormat format) { + updateDatabase.update(node.getId(), format, blob); + } + @Field(keys = {Table.PRIMARY}) private final int nodeId; + @Field + private Timestamp createdAt; + @Field private SchematicFormat nodeFormat; @@ -84,15 +110,19 @@ public class NodeData { } catch (IOException e) { throw new SecurityException("SchemData is wrong", e); } - }, nodeId); + }, nodeId, createdAt); } catch (Exception e) { throw new IOException(e); } } + @Deprecated public void saveFromStream(InputStream blob, SchematicFormat newFormat) { - updateDatabase.update(nodeId, newFormat, blob); - nodeFormat = newFormat; + saveFromStream(SchematicNode.getSchematicNode(nodeId), blob, newFormat); + } + + public void delete() { + delete.update(nodeId, createdAt); } @AllArgsConstructor diff --git a/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java b/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java index 87b7cac4c..531d70ef4 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java +++ b/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java @@ -407,7 +407,7 @@ public class SchematicNode { public String getFileEnding() { if (isDir()) throw new SecurityException("Node is Directory"); - return NodeData.get(this).getNodeFormat().getFileEnding(); + return NodeData.getLatest(this).getNodeFormat().getFileEnding(); } public int getRank() { diff --git a/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java b/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java index 9a0ae4b52..072afaff3 100644 --- a/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java +++ b/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java @@ -145,6 +145,6 @@ public class WorldeditWrapper14 implements WorldeditWrapper { throw new SecurityException(e); } - new SchematicData(schem).saveFromBytes(outputStream.toByteArray(), NodeData.SchematicFormat.SPONGE_V2); + SchematicData.saveFromBytes(schem, outputStream.toByteArray(), NodeData.SchematicFormat.SPONGE_V2); } } diff --git a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java index d0479e46e..1fdd34b7b 100644 --- a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java +++ b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java @@ -140,6 +140,6 @@ public class WorldeditWrapper8 implements WorldeditWrapper { throw new SecurityException(e); } - new SchematicData(schem).saveFromBytes(outputStream.toByteArray(), NodeData.SchematicFormat.MCEDIT); + SchematicData.saveFromBytes(schem, outputStream.toByteArray(), NodeData.SchematicFormat.MCEDIT); } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java index 29ccc4346..2b9548c02 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java @@ -83,13 +83,7 @@ public class PrepareSchem implements Listener { return; } - if(schemExists(schem)) - return; - - SchematicNode old = schem; - schem = SchematicNode.createSchematicNode(schem.getOwner(), preparedName(schem), schem.getParent(), Config.SchematicType.checkType().toDB(), schem.getItem()); - schem.setReplaceColor(old.replaceColor()); - schem.setAllowReplay(old.allowReplay()); + schem.setSchemtype(Config.SchematicType.checkType()); try{ WorldeditWrapper.impl.saveSchem(schem, region, minY); @@ -119,20 +113,5 @@ public class PrepareSchem implements Listener { FightState.setFightState(FightState.PRE_SCHEM_SETUP); FightState.setFightState(FightState.POST_SCHEM_SETUP); } - - schemExists(SchematicNode.getSchematicNode(Config.PrepareSchemID)); - } - - private boolean schemExists(SchematicNode schem) { - if(SchematicNode.getSchematicNode(schem.getOwner(), preparedName(schem), schem.getParent()) != null) { - FightSystem.getMessage().broadcast("PREPARE_SCHEM_EXISTS"); - Bukkit.shutdown(); - return true; - } - return false; - } - - private String preparedName(SchematicNode schem) { - return schem.getName() + "-prepared"; } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java index 73821e6fe..48cbb378e 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java @@ -275,7 +275,7 @@ public interface Recorder { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try{ - copy(NodeData.get(SchematicNode.getSchematicNode(schemId)).schemData(), buffer); + copy(NodeData.getLatest(SchematicNode.getSchematicNode(schemId)).schemData(), buffer); }catch (EOFException e) { Bukkit.getLogger().log(Level.INFO, "EOFException ignored"); } catch (IOException e) { diff --git a/LegacyBauSystem/src/de/steamwar/bausystem/world/ClipboardListener.java b/LegacyBauSystem/src/de/steamwar/bausystem/world/ClipboardListener.java index 6ab684781..0ff91d44f 100644 --- a/LegacyBauSystem/src/de/steamwar/bausystem/world/ClipboardListener.java +++ b/LegacyBauSystem/src/de/steamwar/bausystem/world/ClipboardListener.java @@ -53,7 +53,7 @@ public class ClipboardListener implements Listener { } try { - new SchematicData(schematic).saveFromPlayer(e.getPlayer()); + SchematicData.saveFromPlayer(e.getPlayer(), schematic); } catch (Exception ex) { if (newSchem) { schematic.delete(); diff --git a/SchematicSystem/SchematicSystem_Core/src/SchematicSystem.properties b/SchematicSystem/SchematicSystem_Core/src/SchematicSystem.properties index 29cb8829a..5b8aee8f8 100644 --- a/SchematicSystem/SchematicSystem_Core/src/SchematicSystem.properties +++ b/SchematicSystem/SchematicSystem_Core/src/SchematicSystem.properties @@ -26,6 +26,7 @@ CLICK_DRAG_ITEM=§7Click or drag item here CURRENT=§7Current: {0} CONFIRM=§aConfirm CANCEL=§cCancel +BLANK={0} UTIL_NAME_REQUIRED=§cFolder name required UTIL_NAME_TOO_LONG=§cSchematic name too long @@ -49,6 +50,7 @@ UTIL_LIST_NEXT=Page ({0}/{1}) »» UTIL_LIST_NEXT_HOVER=§eNext page UTIL_INFO_SCHEM=§7Schematic: §e{0} UTIL_INFO_NAME=§7Name: §e{0} +UTIL_INFO_REVISIONS=§7Revisions: §e{0} UTIL_INFO_OWNER=§7Owner: §e{0} UTIL_INFO_PARENT=§7Directory: §e{0} UTIL_INFO_UPDATED=§7Last update: §e{0} @@ -70,6 +72,7 @@ UTIL_INFO_ACTION_TYPE_HOVER=§eChange schematic type UTIL_INFO_ACTION_ADD_HOVER=§eAdd member UTIL_INFO_ACTION_REMOVE_HOVER=§eRemove {0} UTIL_INFO_ACTION_MOVE_HOVER=§eMove schematic +UTIL_INFO_ACTION_REVISIONS_HOVER=§eList revisions UTIL_INFO_ACTION_RENAME_HOVER=§eRename schematic UTIL_INFO_ACTION_DELETE=(Delete) UTIL_INFO_ACTION_DELETE_HOVER=§eDelete schematic @@ -79,6 +82,7 @@ UTIL_LOAD_DIR=§cYou cannot load folders UTIL_LOAD_DONE=§7Schematic §e{0} loaded UTIL_LOAD_NO_DATA=§cNo data could be found in the Schematic UTIL_LOAD_ERROR=§cThe schematic could not be loaded +UTIL_LOAD_ILLEGAL_REVISION=§cThe schematic doesn't have {0} revisions UTIL_DOWNLOAD_PUNISHED=§cYou are not allowed to download schematics: §f§l{0} UTIL_DOWNLOAD_NOT_OWN=§cYou may download only your own schematics UTIL_DOWNLOAD_LINK=Your download link: @@ -224,6 +228,9 @@ GUI_DELETE_MEMBER_TITLE=Remove {0} GUI_DELETE_MEMBER_DONE=Access to Schematic §e{0} §7removed GUI_DELETE_MEMBERS_TITLE=Remove members GUI_CHANGE_ITEM=Change item +GUI_LOAD_LATEST=§eLeft §7Click → §eLoad latest +GUI_LOAD_REVISION=§eRight §7Click → §eList Revisions +GUI_LOAD_REVISION_TITLE=Select Revision AUTO_CHECK_RESULT_NOT_LOAD=The schematic could not be loaded AUTO_CHECK_RESULT_TOO_WIDE=The schematic is too wide ({0} > {1}) @@ -263,4 +270,8 @@ AUTO_CHECKER_RESULT_RECORD=§7Record: §c[{0}, {1}, {2}] AUTO_CHECKER_RESULT_TOO_MANY_DISPENSER_ITEMS=§7Dispenser: §c[{0}, {1}, {2}]§7, §c{3} §7items, Max: §e{4} AUTO_CHECKER_RESULT_FORBIDDEN_ITEM_NBT=§7Forbidden Item NBT: [{0}, {1}, {2}] -> §c{3} AUTO_CHECKER_RESULT_TELEPORT_HERE=§7Teleport to block -AUTO_CHECKER_RESULT_AFTER_DEADLINE=§cThe deadline has expired: {0} \ No newline at end of file +AUTO_CHECKER_RESULT_AFTER_DEADLINE=§cThe deadline has expired: {0} + +REVISIONS_TITLE=§7Revisions: +REVISIONS_REVISION_NUMBER=§7#{0}: §e{1} +REVISIONS_EMPTY=§cNo Revisions \ No newline at end of file diff --git a/SchematicSystem/SchematicSystem_Core/src/SchematicSystem_de.properties b/SchematicSystem/SchematicSystem_Core/src/SchematicSystem_de.properties index 5e85d3469..20205eeed 100644 --- a/SchematicSystem/SchematicSystem_Core/src/SchematicSystem_de.properties +++ b/SchematicSystem/SchematicSystem_Core/src/SchematicSystem_de.properties @@ -90,6 +90,9 @@ UTIL_SUBMIT_DIRECT=§eDirekt einsenden UTIL_SUBMIT_DIRECT_DONE=§aDie Schematic wird zeitnah überprüft UTIL_SUBMIT_EXTEND=§eSchematic ausfahren UTIL_SUBMIT_EXTEND_DONE=§aDer Vorbereitungsserver wird gestartet +UTIL_INFO_ACTION_REVISIONS_HOVER=§eVersionen anzeigen +UTIL_LOAD_ILLEGAL_REVISION=§cDie schematic hat nicht {0} Versionen +UTIL_INFO_REVISIONS=§7Versionen: §e{0} COMMAND_INVALID_NODE=§cDie Schematic konnte nicht gefunden werden COMMAND_NOT_OWN=§cDas darfst du nur bei deinen eigenen Schematics machen @@ -204,6 +207,9 @@ GUI_DELETE_MEMBER_TITLE={0} entfernen GUI_DELETE_MEMBER_DONE=Zugriff zu Schematic §e{0} §7entfernt GUI_DELETE_MEMBERS_TITLE=Mitglieder entfernen GUI_CHANGE_ITEM=Item ändern +GUI_LOAD_LATEST=§eLinks §7Klick → §eLetzte Laden +GUI_LOAD_REVISION=§eRechts §7Klick → §eVersionen anzeigen +GUI_LOAD_REVISION_TITLE=Version Laden AUTO_CHECK_RESULT_NOT_LOAD=Die Schematic konnte nicht geladen werden AUTO_CHECK_RESULT_TOO_WIDE=Die Schematic ist zu breit ({0} > {1}) @@ -242,4 +248,7 @@ AUTO_CHECKER_RESULT_RECORD=§7Schallplatte: §c[{0}, {1}, {2}] AUTO_CHECKER_RESULT_TOO_MANY_DISPENSER_ITEMS=§7Dispenser: §c[{0}, {1}, {2}]§7, §c{3} §7gegenstände, Max: §e{4} AUTO_CHECKER_RESULT_FORBIDDEN_ITEM_NBT=§7Verbotene NBT-Daten: [{0}, {1}, {2}] -> §c{3} AUTO_CHECKER_RESULT_TELEPORT_HERE=§7Zum block teleportieren -AUTO_CHECKER_RESULT_AFTER_DEADLINE=§cDer einsendeschluss ist bereits vorbei: {0} \ No newline at end of file +AUTO_CHECKER_RESULT_AFTER_DEADLINE=§cDer einsendeschluss ist bereits vorbei: {0} + +REVISIONS_TITLE=§7Versionen: +REVISIONS_EMPTY=§cKeine Versionen \ No newline at end of file diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/DownloadCommand.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/DownloadCommand.java index 31c29bd07..3e2f009de 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/DownloadCommand.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/DownloadCommand.java @@ -43,7 +43,7 @@ public class DownloadCommand extends SWCommand { } try { - new SchematicData(copyNode).saveFromPlayer(player); + SchematicData.saveFromPlayer(player, copyNode); } catch (IOException e) { SchematicSystem.MESSAGE.send("DOWNLOAD_ERROR", player); if (newSchem) { diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java index 4160ad051..ec59b16d7 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java @@ -95,9 +95,28 @@ public class GUI { SteamwarUser user = getUser(player); SWInventory inv = new SWInventory(player, 9 * 2, node.generateBreadcrumbs()); if(!node.isDir()) { - inv.setItem(0, SWItem.getMaterial("WOOD_AXE"), SchematicSystem.MESSAGE.parse("GUI_INFO_LOAD", player), click -> { - player.closeInventory(); - SchematicCommandUtils.loadSchem(player, node); + inv.setItem(0, SWItem.getMaterial("WOOD_AXE"), SchematicSystem.MESSAGE.parse("GUI_INFO_LOAD", player), Arrays.asList( + SchematicSystem.MESSAGE.parse("GUI_LOAD_LATEST", player), + SchematicSystem.MESSAGE.parse("GUI_LOAD_REVISION", player) + ), false, click -> { + if (click.isLeftClick()) { + player.closeInventory(); + SchematicCommandUtils.loadSchem(player, node, -1); + } else if (click.isRightClick()) { + List> entries = new ArrayList<>(); + List datas = NodeData.get(node); + for (int i = 0; i < datas.size(); i++) { + entries.add(new SWListInv.SWListEntry<>(new SWItem(SWItem.getMaterial(node.getItem()), "§e" + SchematicSystem.MESSAGE.parse("BLANK", player, datas.get(i).getCreatedAt())), i)); + } + + SWListInv listInv = new SWListInv<>(player, SchematicSystem.MESSAGE.parse("GUI_LOAD_REVISION_TITLE", player, node.generateBreadcrumbs()), entries, (clickType, revision) -> { + if(revision == null) return; + player.closeInventory(); + SchematicCommandUtils.loadSchem(player, node, revision); + }); + listInv.setCallback(-999, click2 -> player.closeInventory()); + listInv.open(); + } }); } diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java index f92c7224d..39fbd137e 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java @@ -223,6 +223,11 @@ public class SchematicCommandUtils { } else { SchematicSystem.MESSAGE.sendPrefixless("UTIL_INFO_PARENT", player, node.getParent() == null ? "/" : node.getParentNode().generateBreadcrumbs()); } + player.spigot().sendMessage( + new ComponentBuilder(SchematicSystem.MESSAGE.parseToComponent("UTIL_INFO_REVISIONS", false, player, NodeData.getRevisions(node))) + .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[] {SchematicSystem.MESSAGE.parseToComponent("UTIL_INFO_ACTION_REVISIONS_HOVER", false, player)})) + .event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem revisions " + node.generateBreadcrumbs())) + .create()); SchematicSystem.MESSAGE.sendPrefixless("UTIL_INFO_UPDATED", player, node.getLastUpdate()); if (!node.isDir()) { if(node.getOwner() == user.getId()) { @@ -357,7 +362,7 @@ public class SchematicCommandUtils { PUBLIC_TOGGLED.remove(player); } - public static void loadSchem(Player player, SchematicNode node) { + public static void loadSchem(Player player, SchematicNode node, int revision) { SteamwarUser user = getUser(player); if(BauServerInfo.isBauServer() && BauServerInfo.getOwnerId() != user.getId() && (Punishment.isPunished(user, Punishment.PunishmentType.NoSchemSharing, punishment -> @@ -372,11 +377,13 @@ public class SchematicCommandUtils { } try { - new SchematicData(node).loadToPlayer(player); + new SchematicData(node, revision).loadToPlayer(player); SchematicSystem.MESSAGE.send("UTIL_LOAD_DONE", player, node.getName()); Bukkit.getLogger().log(Level.INFO, "{0} has loaded Schematic {1} {2}", new Object[]{player.getName(), node.getId(), node.getName()}); } catch (NoClipboardException e) { SchematicSystem.MESSAGE.send("UTIL_LOAD_NO_DATA", player); + } catch (IllegalArgumentException e) { + SchematicSystem.MESSAGE.send("UTIL_LOAD_ILLEGAL_REVISION", player, revision); } catch (Exception e) { SchematicSystem.MESSAGE.send("UTIL_LOAD_ERROR", player); Bukkit.getLogger().log(Level.INFO, e.getMessage(), e); diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/SavePart.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/SavePart.java index 31695f735..3ae0dd6cf 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/SavePart.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/SavePart.java @@ -49,11 +49,11 @@ public class SavePart extends SWCommand { SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectSchematicNode(), schematicNode -> { if(schematicNode == null || schematicNode.isDir()) { SWAnvilInv anvilInv = new SWAnvilInv(player, SchematicSystem.MESSAGE.parse("COMMAND_ENTER_NAME", player)); - anvilInv.setCallback(s -> saveSchem(player, schematicNode==null?s:(schematicNode.generateBreadcrumbs() + s), true)); + anvilInv.setCallback(s -> saveSchem(player, schematicNode==null?s:(schematicNode.generateBreadcrumbs() + s))); anvilInv.setItem(Material.CAULDRON); anvilInv.open(); } else { - saveSchem(player, schematicNode.generateBreadcrumbs(), true); + saveSchem(player, schematicNode.generateBreadcrumbs()); } }); selector.setSingleDirOpen(false); @@ -62,7 +62,7 @@ public class SavePart extends SWCommand { @Register("save") @Register("s") - public void saveSchem(Player player, @AbstractSWCommand.Mapper("stringMapper") String name, @AbstractSWCommand.StaticValue(value = {"", "-f"}, allowISE=true) @AbstractSWCommand.OptionalValue("") boolean overwrite) { + public void saveSchem(Player player, @AbstractSWCommand.Mapper("stringMapper") String name) { SteamwarUser user = getUser(player); if(BauServerInfo.isBauServer() && BauServerInfo.getOwnerId() != user.getId() && (Punishment.isPunished(user, Punishment.PunishmentType.NoSchemReceiving, punishment -> @@ -88,9 +88,6 @@ public class SavePart extends SWCommand { } else if (!node.getSchemtype().writeable() || node.getOwner() != user.getId()) { SchematicSystem.MESSAGE.send("COMMAND_SAVE_NO_OVERWRITE", player); return; - } else if(!overwrite) { - SchematicSystem.MESSAGE.send("COMMAND_SAVE_OVERWRITE_CONFIRM", player, SchematicSystem.MESSAGE.parse("COMMAND_SAVE_OVERWRITE_CONFIRM_HOVER", player), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem s " + name + " -f"), node.generateBreadcrumbs()); - return; } } @@ -101,7 +98,7 @@ public class SavePart extends SWCommand { } try { - new SchematicData(node).saveFromPlayer(player); + SchematicData.saveFromPlayer(player, node); } catch (NoClipboardException e) { SchematicSystem.MESSAGE.send("COMMAND_SAVE_CLIPBOARD_EMPTY", player); if (newSchem) diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ViewPart.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ViewPart.java index 60146d4eb..c1894696e 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ViewPart.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ViewPart.java @@ -21,13 +21,23 @@ package de.steamwar.schematicsystem.commands.schematiccommand.parts; import de.steamwar.command.AbstractSWCommand; import de.steamwar.command.SWCommand; +import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.schematicsystem.commands.schematiccommand.GUI; import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils; import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand; +import de.steamwar.sql.NodeData; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; +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 java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; +import java.util.List; + import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils.*; @AbstractSWCommand.PartOf(SchematicCommand.class) @@ -69,6 +79,25 @@ public class ViewPart extends SWCommand { printSchemInfo(player, node); } + @Register("revisions") + public void revisions(Player player, @Validator("isSchemValidator") SchematicNode node) { + List revisions = NodeData.get(node); + if(revisions.isEmpty()) { + SchematicSystem.MESSAGE.send("REVISIONS_EMPTY", player); + return; + } + + SchematicSystem.MESSAGE.send("REVISIONS_TITLE", player); + for (int j = Math.max(0, revisions.size() - 10); j < revisions.size(); j++) { + player.spigot().sendMessage( + new ComponentBuilder(SchematicSystem.MESSAGE.parseToComponent("REVISIONS_REVISION_NUMBER", false, player, j + 1, revisions.get(j).getCreatedAt())) + .event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem load " + (node.getOwner() == 0 ? "public " : "") + node.generateBreadcrumbs() + " " + (j + 1))) + .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{SchematicSystem.MESSAGE.parseToComponent("UTIL_INFO_ACTION_LOAD_HOVER", false, player)})) + .create() + ); + } + } + @Register(value = "page", noTabComplete = true) public void pageCommand(Player player, int page) { cachedSchemList(player, page); @@ -76,14 +105,14 @@ public class ViewPart extends SWCommand { @Register({"l", "public"}) @Register({"load", "public"}) - public void loadSchemPublic(Player player, @Validator("isSchemValidator") @Mapper("publicMapper") SchematicNode node) { - loadSchem(player, node); + public void loadSchemPublic(Player player, @Validator("isSchemValidator") @Mapper("publicMapper") SchematicNode node, @OptionalValue("-1") int revision) { + loadSchem(player, node, revision); } @Register("l") @Register("load") - public void loadSchem(Player player, @Validator("isSchemValidator") SchematicNode node) { - SchematicCommandUtils.loadSchem(player, node); + public void loadSchem(Player player, @Validator("isSchemValidator") SchematicNode node, @OptionalValue("-1") int revision) { + SchematicCommandUtils.loadSchem(player, node, revision); } @Register("gui") diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java index 5ab944dcd..53cb261db 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java @@ -47,11 +47,25 @@ public class SchematicData { private final NodeData data; public SchematicData(SchematicNode node) { - this.data = NodeData.get(node); + this.data = NodeData.getLatest(node); if(node.isDir()) throw new SecurityException("Node is Directory"); } + public SchematicData(SchematicNode node, int revision) { + if(node.isDir()) + throw new SecurityException("Node is Directory"); + + if (revision < 1) { + this.data = NodeData.getLatest(node); + } else { + if (NodeData.getRevisions(node) < revision) { + throw new IllegalArgumentException("Revision " + revision + " does not exist"); + } + this.data = NodeData.get(node, revision); + } + } + public Clipboard load() throws IOException, NoClipboardException { return WorldEditWrapper.impl.getClipboard(data.schemData(), data.getNodeFormat()); } @@ -60,12 +74,12 @@ public class SchematicData { WorldEditWrapper.impl.setPlayerClipboard(player, data.schemData(), data.getNodeFormat()); } - public void saveFromPlayer(Player player) throws IOException, NoClipboardException { - data.saveFromStream(WorldEditWrapper.impl.getPlayerClipboard(player), WorldEditWrapper.impl.getNativeFormat()); + public static void saveFromPlayer(Player player, SchematicNode node) throws IOException, NoClipboardException { + NodeData.saveFromStream(node, WorldEditWrapper.impl.getPlayerClipboard(player), WorldEditWrapper.impl.getNativeFormat()); } @Deprecated - public void saveFromBytes(byte[] bytes, NodeData.SchematicFormat newFormat) { - data.saveFromStream(new ByteArrayInputStream(bytes), newFormat); + public static void saveFromBytes(SchematicNode node, byte[] bytes, NodeData.SchematicFormat newFormat) { + NodeData.saveFromStream(node, new ByteArrayInputStream(bytes), newFormat); } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java index 4a202368a..f798d3ce7 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java @@ -94,7 +94,7 @@ public class DiscordSchemUpload extends ListenerAdapter { version = NodeData.SchematicFormat.MCEDIT; } - NodeData.get(node).saveFromStream(new ByteArrayInputStream(bytes), version); + NodeData.saveFromStream(node, new ByteArrayInputStream(bytes), version); sender.system("DC_SCHEMUPLOAD_SUCCESS", name); } catch (InterruptedException e) { Thread.currentThread().interrupt(); diff --git a/WebsiteBackend/src/de/steamwar/routes/Schematic.kt b/WebsiteBackend/src/de/steamwar/routes/Schematic.kt index ec3b54fba..7024a6572 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Schematic.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Schematic.kt @@ -89,7 +89,7 @@ fun Route.configureSchematic() { return@get } - val data = NodeData.get(node) ?: run { + val data = NodeData.getLatest(node) ?: run { call.respond(HttpStatusCode.InternalServerError) return@get } @@ -166,8 +166,7 @@ fun Route.configureSchematic() { } catch (_: Exception) {} } - val data = NodeData(node.id, version) - data.saveFromStream(content.inputStream(), version) + NodeData.saveFromStream(node, content.inputStream(), version) call.respond(ResponseSchematic(node)) } catch (e: Exception) { From d04939fb2c06b18c19a00c7f67aa47f96340f828 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 12 Mar 2025 08:41:21 +0100 Subject: [PATCH 098/153] Add a simple smaller Trace file, not finished! --- .../features/tracer/TraceManager.java | 4 +- .../features/tracer/TraceRepository.java | 84 ++++++++++++------- 2 files changed, 57 insertions(+), 31 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceManager.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceManager.java index 213d5e8e1..9e949c9da 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceManager.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceManager.java @@ -58,13 +58,13 @@ public class TraceManager implements Listener { return; for (File traceFile : traceFiles) { - if (traceFile.getName().contains(".records")) + if (traceFile.getName().contains(".meta")) continue; if (TraceRepository.getVersion(traceFile) == TraceRepository.SERIALISATION_VERSION) { add(TraceRepository.readTrace(traceFile)); } else { - String uuid = traceFile.getName().replace(".meta", ""); + String uuid = traceFile.getName().replace(".records", ""); new File(tracesFolder, uuid + ".records").deleteOnExit(); new File(tracesFolder, uuid + ".meta").deleteOnExit(); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRepository.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRepository.java index 39f50fe1c..0f8b8816b 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRepository.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRepository.java @@ -34,17 +34,16 @@ public class TraceRepository { } @SneakyThrows - public static Trace readTrace(File metadataFile) { + public static Trace readTrace(File recordsFile) { @Cleanup - ObjectInputStream reader = new ObjectInputStream(new FileInputStream(metadataFile)); + ObjectInputStream reader = new ObjectInputStream(new FileInputStream(recordsFile)); UUID uuid = UUID.fromString(reader.readUTF()); Region region = Region.getREGION_MAP().get(reader.readUTF()); Date date = (Date) reader.readObject(); - File recordsFile = new File(tracesFolder,uuid + ".records"); int serialisationVersion = reader.readInt(); int recordsCount = reader.readInt(); - return new Trace(uuid, region, date, metadataFile, recordsFile, recordsCount); + return new Trace(uuid, region, date, recordsFile, recordsFile, recordsCount); } @SneakyThrows @@ -53,38 +52,65 @@ public class TraceRepository { outputStream.writeUTF(trace.getUuid().toString()); outputStream.writeUTF(trace.getRegion().getName()); outputStream.writeObject(trace.getDate()); - outputStream.writeInt(SERIALISATION_VERSION); + outputStream.writeInt(SERIALISATION_VERSION + 1); outputStream.writeInt(records.size()); + + Map> pointsByTNTId = new HashMap<>(); + records.forEach(tntPoint -> { + pointsByTNTId.computeIfAbsent(tntPoint.getTntId(), integer -> new ArrayList<>()).add(tntPoint); + }); + + for (Map.Entry> entry : pointsByTNTId.entrySet()) { + outputStream.writeInt(entry.getKey()); + outputStream.write(entry.getValue().size()); + + for (int i = 0; i < entry.getValue().size(); i++) { + TNTPoint current = entry.getValue().get(i); + if (i == 0) { + writeTNTPoint(outputStream, current, true); + continue; + } + + TNTPoint last = entry.getValue().get(i - 1); + + boolean writeTickData = true; + if (last.getTicksSinceStart() + 1 == current.getTicksSinceStart() && last.getFuse() - 1 == current.getFuse()) { + writeTickData = false; + } + + writeTNTPoint(outputStream, current, writeTickData); + } + } + outputStream.flush(); outputStream.close(); - - - writeTraceRecords(trace.getRecordsSaveFile(), records); } @SneakyThrows - protected static void writeTraceRecords(File recordsFile, List records) { - DataOutputStream outputStream = new DataOutputStream(new FileOutputStream(recordsFile)); - for (TNTPoint record : records) { - outputStream.writeInt(record.getTntId()); - outputStream.writeBoolean(record.isExplosion()); - outputStream.writeBoolean(record.isInWater()); - outputStream.writeBoolean(record.isAfterFirstExplosion()); - outputStream.writeBoolean(record.isDestroyedBuildArea()); - outputStream.writeBoolean(record.isDestroyedTestBlock()); - outputStream.writeLong(record.getTicksSinceStart()); - outputStream.writeInt(record.getFuse()); - Location location = record.getLocation(); - outputStream.writeDouble(location.getX()); - outputStream.writeDouble(location.getY()); - outputStream.writeDouble(location.getZ()); - Vector velocity = record.getVelocity(); - outputStream.writeDouble(velocity.getX()); - outputStream.writeDouble(velocity.getY()); - outputStream.writeDouble(velocity.getZ()); + private static void writeTNTPoint(ObjectOutputStream outputStream, TNTPoint tntPoint, boolean writeTickData) { + byte data = 0; + if (writeTickData) data |= 0x01; + if (tntPoint.isExplosion()) data |= 0x02; + if (tntPoint.isInWater()) data |= 0x04; + if (tntPoint.isAfterFirstExplosion()) data |= 0x08; + if (tntPoint.isDestroyedBuildArea()) data |= 0x10; + if (tntPoint.isDestroyedTestBlock()) data |= 0x20; + outputStream.write(data); + + if (writeTickData) { + outputStream.writeLong(tntPoint.getTicksSinceStart()); + outputStream.writeInt(tntPoint.getFuse()); } - outputStream.flush(); - outputStream.close(); + + Location location = tntPoint.getLocation(); + outputStream.writeDouble(location.getX()); + outputStream.writeDouble(location.getY()); + outputStream.writeDouble(location.getZ()); + + Vector velocity = tntPoint.getVelocity(); + outputStream.writeDouble(velocity.getX()); + outputStream.writeDouble(velocity.getY()); + outputStream.writeDouble(velocity.getZ()); } @SneakyThrows From 95a97aed938e2d354b3a6493e7ae298ac910f411 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 2 Jul 2025 09:16:48 +0200 Subject: [PATCH 099/153] Update TraceRepository to save quite a bit smaller traces --- .../bausystem/features/tracer/Trace.java | 16 +-- .../features/tracer/TraceManager.java | 30 +++-- .../tracer/TraceRecordingWrapper.java | 2 +- .../features/tracer/TraceRepository.java | 110 ++++++++++-------- 4 files changed, 84 insertions(+), 74 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java index 9628570a0..2c7cf22c2 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java @@ -50,12 +50,6 @@ public class Trace { @Getter private final File recordsSaveFile; - /** - * File the metadata are saved in - */ - @Getter - private final File metadataSaveFile; - /** * Region the trace was recorded in */ @@ -75,7 +69,7 @@ public class Trace { @Setter @Getter - private int recordsCount; + private int tntIdCount; /** * A map of all REntityServers rendering this trace @@ -95,21 +89,19 @@ public class Trace { this.date = new Date(); records = new SoftReference<>(recordList); recordsSaveFile = new File(TraceRepository.tracesFolder, uuid + ".records"); - metadataSaveFile = new File(TraceRepository.tracesFolder, uuid + ".meta"); } /** * Constructor for deserialising a trace from the file system */ @SneakyThrows - protected Trace(UUID uuid, Region region, Date date, File metadataFile, File recordsFile, int recordsCount) { - this.metadataSaveFile = metadataFile; + protected Trace(UUID uuid, Region region, Date date, File recordsFile, int tntIdCount) { recordsSaveFile = recordsFile; this.uuid = uuid; this.region = region; this.date = date; this.records = new SoftReference<>(null); - this.recordsCount = recordsCount; + this.tntIdCount = tntIdCount; } /** @@ -311,7 +303,7 @@ public class Trace { ", region=" + region + ", creationTime=" + date + ", recordsSaveFile=" + recordsSaveFile.getName() + - ", recordCount=" + recordsCount + + ", tntCount=" + tntIdCount + ", records=" + getRecords() + '}'; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceManager.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceManager.java index 9e949c9da..4a741e779 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceManager.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceManager.java @@ -57,19 +57,27 @@ public class TraceManager implements Listener { if (traceFiles == null) return; + boolean hasMetaFiles = false; for (File traceFile : traceFiles) { - if (traceFile.getName().contains(".meta")) - continue; - - if (TraceRepository.getVersion(traceFile) == TraceRepository.SERIALISATION_VERSION) { - add(TraceRepository.readTrace(traceFile)); - } else { - String uuid = traceFile.getName().replace(".records", ""); - - new File(tracesFolder, uuid + ".records").deleteOnExit(); - new File(tracesFolder, uuid + ".meta").deleteOnExit(); + if (traceFile.getName().contains(".meta")) { + hasMetaFiles = true; } + } + if (hasMetaFiles) { + for (File traceFile : traceFiles) { + traceFile.delete(); + } + traceFiles = new File[0]; + } + // TODO: Cleanup all traces if a .meta is present! + for (File traceFile : traceFiles) { + Trace trace = TraceRepository.readTrace(traceFile); + if (trace == null) { + traceFile.delete(); + continue; + } + add(trace); } } @@ -152,7 +160,6 @@ public class TraceManager implements Listener { if (traceId == null) throw new RuntimeException("Trace not found while trying to remove see (c978eb98-b0b2-4009-91d8-acfa34e2831a)"); traces.remove(traceId); trace.hide(); - trace.getMetadataSaveFile().delete(); trace.getRecordsSaveFile().delete(); } @@ -172,7 +179,6 @@ public class TraceManager implements Listener { tracesByRegion.getOrDefault(region, new HashMap<>()) .forEach((i, trace) -> { if (trace.getRegion() != region) return; - trace.getMetadataSaveFile().delete(); trace.getRecordsSaveFile().delete(); }); tracesByRegion.getOrDefault(region, new HashMap<>()).clear(); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecordingWrapper.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecordingWrapper.java index 82eb30196..38cde80d2 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecordingWrapper.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecordingWrapper.java @@ -65,7 +65,7 @@ public class TraceRecordingWrapper { TraceManager.instance.showPartial(trace, recordsToAdd); recordList.addAll(recordsToAdd); - trace.setRecordsCount(recordList.size()); + trace.setTntIdCount((int) recordList.stream().map(TNTPoint::getTntId).distinct().count()); recordsToAdd.clear(); } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRepository.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRepository.java index 0f8b8816b..3aee95e64 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRepository.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRepository.java @@ -9,60 +9,56 @@ import org.bukkit.util.Vector; import java.io.*; import java.util.*; +import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; public class TraceRepository { /** * Increment this when changing serialisation format */ - public static final int SERIALISATION_VERSION = 1; + public static final int SERIALISATION_VERSION = 2; + public static final int WRITE_TICK_DATA = 0x01; + public static final int EXPLOSION = 0x02; + public static final int IN_WATER = 0x04; + public static final int AFTER_FIRST_EXPLOSION = 0x08; + public static final int DESTROYED_BUILD_AREA = 0x10; + public static final int DESTROYED_TEST_BLOCK = 0x20; public static File tracesFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "traces"); - @SneakyThrows - protected static int getVersion(File metadataFile) { - @Cleanup - ObjectInputStream reader = new ObjectInputStream(new FileInputStream(metadataFile)); - reader.readUTF(); - reader.readUTF(); - reader.readObject(); - try { - int version = reader.readInt(); - return version; - } catch (EOFException e) { - return 0; - } - } - @SneakyThrows public static Trace readTrace(File recordsFile) { @Cleanup - ObjectInputStream reader = new ObjectInputStream(new FileInputStream(recordsFile)); + ObjectInputStream reader = new ObjectInputStream(new GZIPInputStream(new FileInputStream(recordsFile))); UUID uuid = UUID.fromString(reader.readUTF()); Region region = Region.getREGION_MAP().get(reader.readUTF()); Date date = (Date) reader.readObject(); int serialisationVersion = reader.readInt(); - int recordsCount = reader.readInt(); + if (serialisationVersion != SERIALISATION_VERSION) { + return null; + } + int tntIdCount = reader.readInt(); - return new Trace(uuid, region, date, recordsFile, recordsFile, recordsCount); + return new Trace(uuid, region, date, recordsFile, tntIdCount); } @SneakyThrows protected static void writeTrace(Trace trace, List records) { - ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(trace.getMetadataSaveFile())); + ObjectOutputStream outputStream = new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream(trace.getRecordsSaveFile()))); outputStream.writeUTF(trace.getUuid().toString()); outputStream.writeUTF(trace.getRegion().getName()); outputStream.writeObject(trace.getDate()); - outputStream.writeInt(SERIALISATION_VERSION + 1); - outputStream.writeInt(records.size()); + outputStream.writeInt(SERIALISATION_VERSION); Map> pointsByTNTId = new HashMap<>(); records.forEach(tntPoint -> { pointsByTNTId.computeIfAbsent(tntPoint.getTntId(), integer -> new ArrayList<>()).add(tntPoint); }); + outputStream.writeInt(pointsByTNTId.size()); for (Map.Entry> entry : pointsByTNTId.entrySet()) { outputStream.writeInt(entry.getKey()); - outputStream.write(entry.getValue().size()); + outputStream.writeInt(entry.getValue().size()); for (int i = 0; i < entry.getValue().size(); i++) { TNTPoint current = entry.getValue().get(i); @@ -89,12 +85,12 @@ public class TraceRepository { @SneakyThrows private static void writeTNTPoint(ObjectOutputStream outputStream, TNTPoint tntPoint, boolean writeTickData) { byte data = 0; - if (writeTickData) data |= 0x01; - if (tntPoint.isExplosion()) data |= 0x02; - if (tntPoint.isInWater()) data |= 0x04; - if (tntPoint.isAfterFirstExplosion()) data |= 0x08; - if (tntPoint.isDestroyedBuildArea()) data |= 0x10; - if (tntPoint.isDestroyedTestBlock()) data |= 0x20; + if (writeTickData) data |= WRITE_TICK_DATA; + if (tntPoint.isExplosion()) data |= EXPLOSION; + if (tntPoint.isInWater()) data |= IN_WATER; + if (tntPoint.isAfterFirstExplosion()) data |= AFTER_FIRST_EXPLOSION; + if (tntPoint.isDestroyedBuildArea()) data |= DESTROYED_BUILD_AREA; + if (tntPoint.isDestroyedTestBlock()) data |= DESTROYED_TEST_BLOCK; outputStream.write(data); if (writeTickData) { @@ -114,16 +110,24 @@ public class TraceRepository { } @SneakyThrows - protected static TNTPoint readTraceRecord(DataInputStream objectInput) { + protected static TNTPoint readTraceRecord(int tntId, TNTPoint last, ObjectInputStream objectInput) { - int tntId = objectInput.readInt(); - boolean explosion = objectInput.readBoolean(); - boolean inWater = objectInput.readBoolean(); - boolean afterFirstExplosion = objectInput.readBoolean(); - boolean destroyedBuildArea = objectInput.readBoolean(); - boolean destroyedTestBlock = objectInput.readBoolean(); - long ticksSinceStart = objectInput.readLong(); - int fuse = objectInput.readInt(); + int data = objectInput.read(); + boolean explosion = (data & EXPLOSION) > 0; + boolean inWater = (data & IN_WATER) > 0; + boolean afterFirstExplosion = (data & AFTER_FIRST_EXPLOSION) > 0; + boolean destroyedBuildArea = (data & DESTROYED_BUILD_AREA) > 0; + boolean destroyedTestBlock = (data & DESTROYED_TEST_BLOCK) > 0; + + long ticksSinceStart; + int fuse; + if ((data & WRITE_TICK_DATA) > 0) { + ticksSinceStart = objectInput.readLong(); + fuse = objectInput.readInt(); + } else { + ticksSinceStart = last.getTicksSinceStart() + 1; + fuse = last.getFuse() - 1; + } double locX = objectInput.readDouble(); double locY = objectInput.readDouble(); @@ -142,21 +146,29 @@ public class TraceRepository { protected static List readTraceRecords(Trace trace) { File recordsFile = trace.getRecordsSaveFile(); @Cleanup - DataInputStream inputStream = new DataInputStream(new FileInputStream(recordsFile)); + ObjectInputStream inputStream = new ObjectInputStream(new GZIPInputStream(new FileInputStream(recordsFile))); + inputStream.readUTF(); + inputStream.readUTF(); + inputStream.readObject(); + inputStream.readInt(); + inputStream.readInt(); List records = new ArrayList<>(); - for (int i = 0; i < trace.getRecordsCount(); i++) { - records.add(readTraceRecord(inputStream)); - } - Map> histories = new HashMap<>(); - for (TNTPoint record : records) { - int tntId = record.getTntId(); - List history = histories.computeIfAbsent(tntId, id -> new ArrayList<>()); - history.add(record); - record.setHistory(history); - } + for (int i = 0; i < trace.getTntIdCount(); i++) { + int tntId = inputStream.readInt(); + int size = inputStream.readInt(); + List points = histories.computeIfAbsent(tntId, id -> new ArrayList<>()); + TNTPoint last = null; + for (int j = 0; j < size; j++) { + TNTPoint point = readTraceRecord(tntId, last, inputStream); + point.setHistory(points); + points.add(point); + last = point; + records.add(point); + } + } return records; } } From 60a70dfc404b756af3345f5c5f2adac7bcb86d14 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 2 Jul 2025 09:59:09 +0200 Subject: [PATCH 100/153] Remove unused get --- .../SQL/src/de/steamwar/sql/AuditLog.java | 44 +++++++++---------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/AuditLog.java b/CommonCore/SQL/src/de/steamwar/sql/AuditLog.java index 82d07c1b9..bc6bdf051 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/AuditLog.java +++ b/CommonCore/SQL/src/de/steamwar/sql/AuditLog.java @@ -80,46 +80,42 @@ public class AuditLog { GUI_CLICK, } - public static AuditLog get(int auditLogId) { - return byId.select(auditLogId); + private static void create(String serverName, SteamwarUser serverOwner, SteamwarUser actor, Type actionType, String text) { + create.insertGetKey(Timestamp.from(Instant.now()), serverName, serverOwner, actor, actionType, text); } - private static AuditLog create(String serverName, SteamwarUser serverOwner, SteamwarUser actor, Type actionType, String text) { - return get(create.insertGetKey(Timestamp.from(Instant.now()), serverName, serverOwner, actor, actionType, text)); + public static void createJoin(@NonNull String jointServerName, SteamwarUser serverOwner, @NonNull SteamwarUser joinedPlayer) { + create(jointServerName, serverOwner, joinedPlayer, Type.JOIN, ""); } - public static AuditLog createJoin(@NonNull String jointServerName, SteamwarUser serverOwner, @NonNull SteamwarUser joinedPlayer) { - return create(jointServerName, serverOwner, joinedPlayer, Type.JOIN, ""); + public static void createLeave(@NonNull String leftServerName, SteamwarUser serverOwner, @NonNull SteamwarUser joinedPlayer) { + create(leftServerName, serverOwner, joinedPlayer, Type.LEAVE, ""); } - public static AuditLog createLeave(@NonNull String leftServerName, SteamwarUser serverOwner, @NonNull SteamwarUser joinedPlayer) { - return create(leftServerName, serverOwner, joinedPlayer, Type.LEAVE, ""); + public static void createCommand(@NonNull String serverName, SteamwarUser serverOwner, SteamwarUser player, @NonNull String command) { + if (player == null) return; + create(serverName, serverOwner, player, Type.COMMAND, command); } - public static AuditLog createCommand(@NonNull String serverName, SteamwarUser serverOwner, SteamwarUser player, @NonNull String command) { - if (player == null) return null; - return create(serverName, serverOwner, player, Type.COMMAND, command); + public static void createSensitiveCommand(@NonNull String serverName, SteamwarUser serverOwner, SteamwarUser player, @NonNull String command) { + if (player == null) return; + create(serverName, serverOwner, player, Type.SENSITIVE_COMMAND, command); } - public static AuditLog createSensitiveCommand(@NonNull String serverName, SteamwarUser serverOwner, SteamwarUser player, @NonNull String command) { - if (player == null) return null; - return create(serverName, serverOwner, player, Type.SENSITIVE_COMMAND, command); + public static void createChat(@NonNull String serverName, SteamwarUser serverOwner, @NonNull SteamwarUser chatter, @NonNull String chat) { + create(serverName, serverOwner, chatter, Type.CHAT, chat); } - public static AuditLog createChat(@NonNull String serverName, SteamwarUser serverOwner, @NonNull SteamwarUser chatter, @NonNull String chat) { - return create(serverName, serverOwner, chatter, Type.CHAT, chat); + public static void createGuiOpen(@NonNull String serverName, SteamwarUser serverOwner, @NonNull SteamwarUser player, @NonNull String guiName) { + create(serverName, serverOwner, player, Type.GUI_OPEN, guiName); } - public static AuditLog createGuiOpen(@NonNull String serverName, SteamwarUser serverOwner, @NonNull SteamwarUser player, @NonNull String guiName) { - return create(serverName, serverOwner, player, Type.GUI_OPEN, guiName); + public static void createGuiClick(@NonNull String serverName, SteamwarUser serverOwner, @NonNull SteamwarUser player, @NonNull String guiName, @NonNull String clickType, int slot, @NonNull String itemName) { + create(serverName, serverOwner, player, Type.GUI_CLICK, "Gui: " + guiName + "\nSlot: " + slot + "\nClickType: " + clickType + "\nItemName: " + itemName); } - public static AuditLog createGuiClick(@NonNull String serverName, SteamwarUser serverOwner, @NonNull SteamwarUser player, @NonNull String guiName, @NonNull String clickType, int slot, @NonNull String itemName) { - return create(serverName, serverOwner, player, Type.GUI_CLICK, "Gui: " + guiName + "\nSlot: " + slot + "\nClickType: " + clickType + "\nItemName: " + itemName); - } - - public static AuditLog createGuiClose(@NonNull String serverName, SteamwarUser serverOwner, @NonNull SteamwarUser player, @NonNull String guiName) { - return create(serverName, serverOwner, player, Type.GUI_CLOSE, guiName); + public static void createGuiClose(@NonNull String serverName, SteamwarUser serverOwner, @NonNull SteamwarUser player, @NonNull String guiName) { + create(serverName, serverOwner, player, Type.GUI_CLOSE, guiName); } public SteamwarUser getServerOwner() { From 4bd5d9eb0b039c978f087fa875aa2087c6be8d60 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 2 Jul 2025 10:00:43 +0200 Subject: [PATCH 101/153] Remove unused get and query --- CommonCore/SQL/src/de/steamwar/sql/AuditLog.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/AuditLog.java b/CommonCore/SQL/src/de/steamwar/sql/AuditLog.java index bc6bdf051..ffe093a01 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/AuditLog.java +++ b/CommonCore/SQL/src/de/steamwar/sql/AuditLog.java @@ -19,7 +19,10 @@ package de.steamwar.sql; -import de.steamwar.sql.internal.*; +import de.steamwar.sql.internal.Field; +import de.steamwar.sql.internal.SqlTypeMapper; +import de.steamwar.sql.internal.Statement; +import de.steamwar.sql.internal.Table; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NonNull; @@ -38,14 +41,8 @@ public class AuditLog { private static final Table table = new Table<>(AuditLog.class); - private static final SelectStatement byId = table.select(Table.PRIMARY); - private static final Statement create = table.insertFields(true, "time", "serverName", "serverOwner", "actor", "actionType", "actionText"); - @Getter - @Field(keys = {Table.PRIMARY}, autoincrement = true) - private final int auditLogId; - @Getter @Field private final Timestamp time; From 6efbda669e79d569c084db0e5e47566b8fdefbda Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 2 Jul 2025 11:17:55 +0200 Subject: [PATCH 102/153] Optimize and improve VelocityCore size Improve steamwar.devserver.gradle to not upload anything that is up to date! --- .../build.gradle.kts | 12 ++++++++++ .../de/steamwar/discord/Dependencies.java} | 6 ++--- VelocityCore/build.gradle.kts | 12 ++-------- .../steamwar/velocitycore/VelocityCore.java | 2 +- buildSrc/src/steamwar.devserver.gradle | 23 ++++++++++++++++--- settings.gradle.kts | 2 +- 6 files changed, 39 insertions(+), 18 deletions(-) rename VelocityCore/{DiscordDependency => Dependencies}/build.gradle.kts (83%) rename VelocityCore/{DiscordDependency/src/de/steamwar/discord/Discord.java => Dependencies/src/de/steamwar/discord/Dependencies.java} (88%) diff --git a/VelocityCore/DiscordDependency/build.gradle.kts b/VelocityCore/Dependencies/build.gradle.kts similarity index 83% rename from VelocityCore/DiscordDependency/build.gradle.kts rename to VelocityCore/Dependencies/build.gradle.kts index dbe2ac56e..d71a6c108 100644 --- a/VelocityCore/DiscordDependency/build.gradle.kts +++ b/VelocityCore/Dependencies/build.gradle.kts @@ -22,6 +22,10 @@ plugins { alias(libs.plugins.shadow) } +tasks.build { + finalizedBy(tasks.shadowJar) +} + java { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 @@ -34,4 +38,12 @@ dependencies { implementation(libs.jda) { exclude(module = "opus-java") } + + implementation(libs.sqlite) + implementation(libs.mysql) + + implementation(libs.msgpack) + implementation(libs.apolloprotos) + + implementation(libs.nbt) } \ No newline at end of file diff --git a/VelocityCore/DiscordDependency/src/de/steamwar/discord/Discord.java b/VelocityCore/Dependencies/src/de/steamwar/discord/Dependencies.java similarity index 88% rename from VelocityCore/DiscordDependency/src/de/steamwar/discord/Discord.java rename to VelocityCore/Dependencies/src/de/steamwar/discord/Dependencies.java index e45486976..f3b2a2431 100644 --- a/VelocityCore/DiscordDependency/src/de/steamwar/discord/Discord.java +++ b/VelocityCore/Dependencies/src/de/steamwar/discord/Dependencies.java @@ -22,8 +22,8 @@ package de.steamwar.discord; import com.velocitypowered.api.plugin.Plugin; @Plugin( - id = "discordvelocitycore", - name = "DiscordVelocityCore" + id = "depencendiesvelocitycore", + name = "DepencendiesVelocityCore" ) -public class Discord { +public class Dependencies { } diff --git a/VelocityCore/build.gradle.kts b/VelocityCore/build.gradle.kts index 5074c280c..91121ea32 100644 --- a/VelocityCore/build.gradle.kts +++ b/VelocityCore/build.gradle.kts @@ -51,18 +51,10 @@ dependencies { compileOnly(libs.viavelocity) compileOnly(project(":VelocityCore:Persistent", "default")) - compileOnly(project(":VelocityCore:DiscordDependency", "default")) + compileOnly(project(":VelocityCore:Dependencies", "default")) implementation(project(":CommonCore")) implementation(project(":CommandFramework")) - - implementation(libs.sqlite) - implementation(libs.mysql) - - implementation(libs.msgpack) - implementation(libs.apolloprotos) - - implementation(libs.nbt) } tasks.register("DevVelocity") { @@ -70,6 +62,6 @@ tasks.register("DevVelocity") { description = "Run a Dev Velocity" dependsOn(":VelocityCore:shadowJar") dependsOn(":VelocityCore:Persistent:jar") - dependsOn(":VelocityCore:DiscordDependency:jar") + dependsOn(":VelocityCore:Dependencies:shadowJar") template = "DevVelocity" } diff --git a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java index 22b64f645..aa98a034f 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java +++ b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java @@ -60,7 +60,7 @@ import java.util.logging.Logger; @Plugin( id = "velocitycore", name = "VelocityCore", - dependencies = { @Dependency(id = "persistentvelocitycore"), @Dependency(id = "discordvelocitycore") } + dependencies = { @Dependency(id = "persistentvelocitycore"), @Dependency(id = "depencendiesvelocitycore") } ) public class VelocityCore implements ReloadablePlugin { diff --git a/buildSrc/src/steamwar.devserver.gradle b/buildSrc/src/steamwar.devserver.gradle index 53f8be3da..5d75c0875 100644 --- a/buildSrc/src/steamwar.devserver.gradle +++ b/buildSrc/src/steamwar.devserver.gradle @@ -46,6 +46,19 @@ class DevServer extends DefaultTask { DevServer() { super() + List upToDateTasks = [] + project.gradle.taskGraph.addTaskExecutionListener(new TaskExecutionListener() { + @Override + void beforeExecute(Task task) { + } + + @Override + void afterExecute(Task task, TaskState state) { + if (state.upToDate) { + upToDateTasks.add(task); + } + } + }) doFirst { List projects = [] projects.add(project) @@ -70,7 +83,7 @@ class DevServer extends DefaultTask { } doLast { checkHasTemplate() - uploadDependencies() + uploadDependencies(upToDateTasks) startDevServer() } finalizedBy(new Finalizer()) @@ -107,7 +120,7 @@ class DevServer extends DefaultTask { } } - void uploadDependencies() { + void uploadDependencies(List upToDateTasks) { def base = plugins == null ? "$template/plugins" : plugins println("Uploading to ~/$base") this.dependsOn.forEach { @@ -119,8 +132,12 @@ class DevServer extends DefaultTask { } else { throw new GradleException("Illegal argument for uploading dependencies") } - def archive = archiveTask.archiveFile.get().asFile + if (upToDateTasks.contains(archiveTask)) { + println("Skipping $archive") + return + } + println("Uploading $archive") new ProcessBuilder("ssh", host, "-T", "rm $base/${archive.name.replace("-all", "")}").start().waitFor() new ProcessBuilder("scp", archive.absolutePath, "$host:~/$base/${archive.name.replace("-all", "")}").start().waitFor() diff --git a/settings.gradle.kts b/settings.gradle.kts index cb1758820..8ab618ffd 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -247,7 +247,7 @@ include("TutorialSystem") include( "VelocityCore", - "VelocityCore:DiscordDependency", + "VelocityCore:Dependencies", "VelocityCore:Persistent" ) From 3b67048b9c1424452cf9d50de08c0eeeeb2a5e9b Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 2 Jul 2025 11:22:36 +0200 Subject: [PATCH 103/153] Improve jar size --- VelocityCore/Dependencies/build.gradle.kts | 12 ++++++++++++ VelocityCore/build.gradle.kts | 13 ------------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/VelocityCore/Dependencies/build.gradle.kts b/VelocityCore/Dependencies/build.gradle.kts index d71a6c108..009768d06 100644 --- a/VelocityCore/Dependencies/build.gradle.kts +++ b/VelocityCore/Dependencies/build.gradle.kts @@ -22,6 +22,18 @@ plugins { alias(libs.plugins.shadow) } +tasks.shadowJar { + exclude("META-INF/*") + exclude("org/sqlite/native/FreeBSD/**', 'org/sqlite/native/Mac/**', 'org/sqlite/native/Windows/**', 'org/sqlite/native/Linux-Android/**', 'org/sqlite/native/Linux-Musl/**") + exclude("org/sqlite/native/Linux/aarch64/**', 'org/sqlite/native/Linux/arm/**', 'org/sqlite/native/Linux/armv6/**', 'org/sqlite/native/Linux/armv7/**', 'org/sqlite/native/Linux/ppc64/**', 'org/sqlite/native/Linux/x86/**") + exclude("org/slf4j/**") + //https://imperceptiblethoughts.com/shadow/configuration/minimizing/ + minimize { + exclude(dependency("mysql:mysql-connector-java:.*")) + } + duplicatesStrategy = DuplicatesStrategy.INCLUDE +} + tasks.build { finalizedBy(tasks.shadowJar) } diff --git a/VelocityCore/build.gradle.kts b/VelocityCore/build.gradle.kts index 91121ea32..f290ed220 100644 --- a/VelocityCore/build.gradle.kts +++ b/VelocityCore/build.gradle.kts @@ -22,19 +22,6 @@ plugins { alias(libs.plugins.shadow) } -tasks.shadowJar { - exclude("META-INF/*") - exclude("org/sqlite/native/FreeBSD/**', 'org/sqlite/native/Mac/**', 'org/sqlite/native/Windows/**', 'org/sqlite/native/Linux-Android/**', 'org/sqlite/native/Linux-Musl/**") - exclude("org/sqlite/native/Linux/aarch64/**', 'org/sqlite/native/Linux/arm/**', 'org/sqlite/native/Linux/armv6/**', 'org/sqlite/native/Linux/armv7/**', 'org/sqlite/native/Linux/ppc64/**', 'org/sqlite/native/Linux/x86/**") - exclude("org/slf4j/**") - //https://imperceptiblethoughts.com/shadow/configuration/minimizing/ - minimize { - exclude(project(":VelocityCore")) - exclude(dependency("mysql:mysql-connector-java:.*")) - } - duplicatesStrategy = DuplicatesStrategy.INCLUDE -} - tasks.build { finalizedBy(tasks.shadowJar) } From e56c41ca6617b7cf1031527d3c41503b1cc8835a Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 2 Jul 2025 11:36:06 +0200 Subject: [PATCH 104/153] Improve dependency upload --- buildSrc/src/steamwar.devserver.gradle | 33 +++++++++++++------------- steamwarci.yml | 2 +- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/buildSrc/src/steamwar.devserver.gradle b/buildSrc/src/steamwar.devserver.gradle index 5d75c0875..3c5cf8820 100644 --- a/buildSrc/src/steamwar.devserver.gradle +++ b/buildSrc/src/steamwar.devserver.gradle @@ -1,3 +1,5 @@ +import java.security.MessageDigest + /* * This file is a part of the SteamWar software. * @@ -46,19 +48,6 @@ class DevServer extends DefaultTask { DevServer() { super() - List upToDateTasks = [] - project.gradle.taskGraph.addTaskExecutionListener(new TaskExecutionListener() { - @Override - void beforeExecute(Task task) { - } - - @Override - void afterExecute(Task task, TaskState state) { - if (state.upToDate) { - upToDateTasks.add(task); - } - } - }) doFirst { List projects = [] projects.add(project) @@ -83,7 +72,7 @@ class DevServer extends DefaultTask { } doLast { checkHasTemplate() - uploadDependencies(upToDateTasks) + uploadDependencies() startDevServer() } finalizedBy(new Finalizer()) @@ -120,7 +109,7 @@ class DevServer extends DefaultTask { } } - void uploadDependencies(List upToDateTasks) { + void uploadDependencies() { def base = plugins == null ? "$template/plugins" : plugins println("Uploading to ~/$base") this.dependsOn.forEach { @@ -132,8 +121,20 @@ class DevServer extends DefaultTask { } else { throw new GradleException("Illegal argument for uploading dependencies") } + def archive = archiveTask.archiveFile.get().asFile - if (upToDateTasks.contains(archiveTask)) { + + Process process = new ProcessBuilder("ssh", host, "-T", "sha1sum $base/${archive.name.replace("-all", "")}").start(); + byte[] bytes = MessageDigest.getInstance("sha1").digest(archive.bytes) + StringBuilder sb = new StringBuilder() + for (byte b : bytes) { + sb.append(String.format("%02X", b)) + } + boolean same = false + process.inputStream.readLines().forEach { + same |= it.startsWith(sb.toString().toLowerCase()) + } + if (same) { println("Skipping $archive") return } diff --git a/steamwarci.yml b/steamwarci.yml index d62f6b621..5548033ad 100644 --- a/steamwarci.yml +++ b/steamwarci.yml @@ -29,7 +29,7 @@ artifacts: "/jars/TutorialSystem.jar": "TutorialSystem/build/libs/TutorialSystem.jar" "/jars/PersistentVelocityCore.jar": "VelocityCore/Persistent/build/libs/Persistent.jar" - "/jars/DiscordVelocityCore.jar": "VelocityCore/DiscordDependency/build/libs/DiscordDependency.jar" + "/jars/DependenciesVelocityCore.jar": "VelocityCore/Dependencies/build/libs/Dependencies-all.jar" "/jars/VelocityCore.jar": "VelocityCore/build/libs/VelocityCore-all.jar" "/usr/local/bin/deployarena.py": "VelocityCore/deployarena.py" From 60347bc481c3984e201b5160624a6f0fdcf30d6f Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 2 Jul 2025 11:53:24 +0200 Subject: [PATCH 105/153] Hotfix dependencies --- VelocityCore/Dependencies/build.gradle.kts | 3 --- 1 file changed, 3 deletions(-) diff --git a/VelocityCore/Dependencies/build.gradle.kts b/VelocityCore/Dependencies/build.gradle.kts index 009768d06..fab7a7f00 100644 --- a/VelocityCore/Dependencies/build.gradle.kts +++ b/VelocityCore/Dependencies/build.gradle.kts @@ -28,9 +28,6 @@ tasks.shadowJar { exclude("org/sqlite/native/Linux/aarch64/**', 'org/sqlite/native/Linux/arm/**', 'org/sqlite/native/Linux/armv6/**', 'org/sqlite/native/Linux/armv7/**', 'org/sqlite/native/Linux/ppc64/**', 'org/sqlite/native/Linux/x86/**") exclude("org/slf4j/**") //https://imperceptiblethoughts.com/shadow/configuration/minimizing/ - minimize { - exclude(dependency("mysql:mysql-connector-java:.*")) - } duplicatesStrategy = DuplicatesStrategy.INCLUDE } From d5ca1e14e194f8fe3e970fd50f61087c749ef89a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 2 Jul 2025 12:25:58 +0200 Subject: [PATCH 106/153] Add prepared flag to schematics and refactor related logic --- .../src/de/steamwar/sql/SchematicNode.java | 65 +++++++++++++------ .../de/steamwar/fightsystem/FightSystem.java | 8 +-- .../fightsystem/fight/FightSchematic.java | 6 +- .../steamwar/fightsystem/fight/FightTeam.java | 4 ++ .../fightsystem/listener/PrepareSchem.java | 1 + .../SchematicCommandUtils.java | 2 + .../velocitycore/commands/CheckCommand.java | 6 +- 7 files changed, 64 insertions(+), 28 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java b/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java index 531d70ef4..1bfa1f9e3 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java +++ b/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java @@ -42,13 +42,13 @@ public class SchematicNode { TAB_CACHE.clear(); } - private static final String nodeSelector = "SELECT NodeId, NodeOwner, NodeOwner AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, ReplaceColor, AllowReplay FROM SchematicNode "; + private static final String nodeSelector = "SELECT NodeId, NodeOwner, NodeOwner AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode "; private static final Table table = new Table<>(SchematicNode.class); private static final Statement create = table.insertFields(true, "NodeOwner", "NodeName", "ParentNode", "NodeItem", "NodeType"); private static final Statement update = table.update(Table.PRIMARY, "NodeName", "ParentNode", "NodeItem", - "NodeType", "NodeRank", "ReplaceColor", "AllowReplay"); + "NodeType", "NodeRank", "Config"); private static final Statement delete = table.delete(Table.PRIMARY); private static final SelectStatement byId = new SelectStatement<>(table, @@ -66,13 +66,13 @@ public class SchematicNode { private static final SelectStatement all = new SelectStatement<>(table, "WITH RECURSIVE Nodes AS (SELECT NodeId, ParentId as ParentNode FROM NodeMember WHERE UserId = ? UNION SELECT NodeId, ParentNode FROM SchematicNode WHERE NodeOwner = ?), RSN AS ( SELECT NodeId, ParentNode FROM Nodes UNION SELECT SN.NodeId, SN.ParentNode FROM SchematicNode SN, RSN WHERE SN.ParentNode = RSN.NodeId ) SELECT SN.*, ? AS EffectiveOwner FROM RSN INNER JOIN SchematicNode SN ON RSN.NodeId = SN.NodeId"); private static final SelectStatement list = new SelectStatement<>(table, - "SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, NM.ParentId AS ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, ReplaceColor, AllowReplay FROM SchematicNode INNER JOIN NodeMember NM on SchematicNode.NodeId = NM.NodeId WHERE NM.ParentId " + "SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, NM.ParentId AS ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode INNER JOIN NodeMember NM on SchematicNode.NodeId = NM.NodeId WHERE NM.ParentId " + Statement.NULL_SAFE_EQUALS - + "? AND NM.UserId = ? UNION ALL SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, ReplaceColor, AllowReplay FROM SchematicNode WHERE (? IS NULL AND ParentNode IS NULL AND NodeOwner = ?) OR (? IS NOT NULL AND ParentNode = ?) ORDER BY NodeName"); + + "? AND NM.UserId = ? UNION ALL SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode WHERE (? IS NULL AND ParentNode IS NULL AND NodeOwner = ?) OR (? IS NOT NULL AND ParentNode = ?) ORDER BY NodeName"); private static final SelectStatement byParentName = new SelectStatement<>(table, - "SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, NM.ParentId AS ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, ReplaceColor, AllowReplay FROM SchematicNode INNER JOIN NodeMember NM on SchematicNode.NodeId = NM.NodeId WHERE NM.ParentId " + "SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, NM.ParentId AS ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode INNER JOIN NodeMember NM on SchematicNode.NodeId = NM.NodeId WHERE NM.ParentId " + Statement.NULL_SAFE_EQUALS - + "? AND NM.UserId = ? AND SchematicNode.NodeName = ? UNION ALL SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, ReplaceColor, AllowReplay FROM SchematicNode WHERE ((? IS NULL AND ParentNode IS NULL AND NodeOwner = ?) OR (? IS NOT NULL AND ParentNode = ?)) AND NodeName = ?"); + + "? AND NM.UserId = ? AND SchematicNode.NodeName = ? UNION ALL SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode WHERE ((? IS NULL AND ParentNode IS NULL AND NodeOwner = ?) OR (? IS NOT NULL AND ParentNode = ?)) AND NodeName = ?"); private static final SelectStatement schematicAccessibleForUser = new SelectStatement<>(table, "WITH RECURSIVE Nodes AS (SELECT NodeId, ParentId as ParentNode FROM NodeMember WHERE UserId = ? UNION SELECT NodeId, ParentNode FROM SchematicNode WHERE NodeOwner = ?), RSN AS ( SELECT NodeId, ParentNode FROM Nodes UNION SELECT SN.NodeId, SN.ParentNode FROM SchematicNode SN, RSN WHERE SN.ParentNode = RSN.NodeId ) SELECT SN.*, ? AS EffectiveOwner FROM RSN INNER JOIN SchematicNode SN ON RSN.NodeId = SN.NodeId WHERE NodeId = ?"); private static final SelectStatement accessibleByUserTypeInParent = new SelectStatement<>(table, @@ -81,7 +81,7 @@ public class SchematicNode { private static final SelectStatement accessibleByUserType = new SelectStatement<>(table, "WITH RECURSIVE Nodes AS (SELECT NodeId, ParentId as ParentNode FROM NodeMember WHERE UserId = ? UNION SELECT NodeId, ParentNode FROM SchematicNode WHERE NodeOwner = ?), RSN AS ( SELECT NodeId, ParentNode FROM Nodes UNION SELECT SN.NodeId, SN.ParentNode FROM SchematicNode SN, RSN WHERE SN.ParentNode = RSN.NodeId ) SELECT SN.*, ? AS EffectiveOwner FROM RSN INNER JOIN SchematicNode SN ON RSN.NodeId = SN.NodeId WHERE NodeType = ?"); private static final SelectStatement byIdAndUser = new SelectStatement<>(table, - "SELECT NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, ReplaceColor, AllowReplay FROM SchematicNode WHERE NodeId = ?"); + "SELECT NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode WHERE NodeId = ?"); private static final SelectStatement allParentsOfNode = new SelectStatement<>(table, "WITH RECURSIVE R AS (SELECT NodeId, ParentNode FROM EffectiveSchematicNode WHERE NodeId = ? AND EffectiveOwner = ? UNION SELECT E.NodeId, E.ParentNode FROM R, EffectiveSchematicNode E WHERE R.ParentNode = E.NodeId AND E.EffectiveOwner = ?) SELECT SN.NodeId, SN.NodeOwner, ? AS EffectiveOwner, SN.NodeName, R.ParentNode, SN.LastUpdate, SN.NodeItem, SN.NodeType, SN.NodeRank, SN.ReplaceColor, SN.AllowReplay FROM R INNER JOIN SchematicNode SN ON SN.NodeId = R.NodeId"); @@ -108,10 +108,8 @@ public class SchematicNode { private SchematicType nodeType; @Field(def = "0") private int nodeRank; - @Field(def = "1") - private boolean replaceColor; - @Field(def = "1") - private boolean allowReplay; + @Field + private int config; private String brCache; @@ -125,8 +123,7 @@ public class SchematicNode { String nodeItem, SchematicType nodeType, int nodeRank, - boolean replaceColor, - boolean allowReplay) { + int config) { this.nodeId = nodeId; this.nodeOwner = nodeOwner; this.effectiveOwner = effectiveOwner; @@ -136,8 +133,7 @@ public class SchematicNode { this.nodeType = nodeType; this.lastUpdate = lastUpdate; this.nodeRank = nodeRank; - this.replaceColor = replaceColor; - this.allowReplay = allowReplay; + this.config = config; } public static List getAll(SteamwarUser user) { @@ -441,24 +437,45 @@ public class SchematicNode { } public boolean replaceColor() { - return replaceColor; + return getConfig(ConfigFlags.REPLACE_COLOR); } public void setReplaceColor(boolean replaceColor) { if (isDir()) throw new SecurityException("Is Directory"); - this.replaceColor = replaceColor; - updateDB(); + setConfig(ConfigFlags.REPLACE_COLOR, replaceColor); } public boolean allowReplay() { - return allowReplay; + return getConfig(ConfigFlags.ALLOW_REPLAY); } public void setAllowReplay(boolean allowReplay) { if (isDir()) throw new SecurityException("Is Directory"); - this.allowReplay = allowReplay; + setConfig(ConfigFlags.ALLOW_REPLAY, allowReplay); + } + + public boolean isPrepared() { + return getConfig(ConfigFlags.IS_PREPARED); + } + + public void setPrepared(boolean prepared) { + if (isDir()) + throw new SecurityException("Is Directory"); + setConfig(ConfigFlags.IS_PREPARED, prepared); + } + + public boolean getConfig(ConfigFlags flag) { + return (config & (1 << flag.ordinal())) == 1; + } + + public void setConfig(ConfigFlags flag, boolean value) { + if (value) { + config |= (1 << flag.ordinal()); + } else { + config &= ~(1 << flag.ordinal()); + } updateDB(); } @@ -486,7 +503,7 @@ public class SchematicNode { private void updateDB() { this.lastUpdate = Timestamp.from(Instant.now()); - update.update(nodeName, parentNode, nodeItem, nodeType, nodeRank, replaceColor, allowReplay, nodeId); + update.update(nodeName, parentNode, nodeItem, nodeType, nodeRank, config, nodeId); TAB_CACHE.clear(); } @@ -608,4 +625,10 @@ public class SchematicNode { TAB_CACHE.computeIfAbsent(user.getId(), integer -> new HashMap<>()).putIfAbsent(cacheKey, list); return list; } + + public static enum ConfigFlags { + REPLACE_COLOR, + ALLOW_REPLAY, + IS_PREPARED + } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 9ebc4f0c9..d602ed0bd 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -41,6 +41,7 @@ import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.utils.*; import de.steamwar.fightsystem.winconditions.*; import de.steamwar.message.Message; +import de.steamwar.sql.NodeData; import de.steamwar.sql.SchematicNode; import lombok.Getter; import org.bukkit.Bukkit; @@ -173,11 +174,8 @@ public class FightSystem extends JavaPlugin { SchematicNode checkSchematicNode = SchematicNode.getSchematicNode(Config.CheckSchemID); Fight.getBlueTeam().setSchem(checkSchematicNode); - if (checkSchematicNode.getName().endsWith("-prepared")) { - SchematicNode unpreparedSchematicNode = SchematicNode.getSchematicNode(checkSchematicNode.getOwner(), checkSchematicNode.getName().substring(0, checkSchematicNode.getName().length() - 9), checkSchematicNode.getParent()); - if (unpreparedSchematicNode != null) { - Fight.getRedTeam().setSchem(unpreparedSchematicNode); - } + if (checkSchematicNode.isPrepared()) { + Fight.getRedTeam().setSchem(checkSchematicNode, NodeData.getRevisions(checkSchematicNode) - 1); } new TechareaCommand(); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index d566c0224..fa9b9c246 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -74,9 +74,13 @@ public class FightSchematic extends StateDependent { } public void setSchematic(SchematicNode schem) { + setSchematic(schem, -1); + } + + public void setSchematic(SchematicNode schem, int revision) { schematic = schem.getId(); try { - clipboard = new SchematicData(schem).load(); + clipboard = new SchematicData(schem, revision).load(); if(schem.replaceColor()) replaceTeamColor(clipboard); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 0cb68f719..a5464a3e8 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -412,6 +412,10 @@ public class FightTeam { } public void setSchem(SchematicNode schematic){ + setSchem(schematic, -1); + } + + public void setSchem(SchematicNode schematic, int revision){ this.schematic.setSchematic(schematic); broadcast("SCHEMATIC_CHOSEN", Config.GameName, schematic.getName()); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java index 2b9548c02..f02beeed5 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java @@ -84,6 +84,7 @@ public class PrepareSchem implements Listener { } schem.setSchemtype(Config.SchematicType.checkType()); + schem.setPrepared(true); try{ WorldeditWrapper.impl.saveSchem(schem, region, minY); diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java index 39fbd137e..b7b610841 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java @@ -428,6 +428,8 @@ public class SchematicCommandUtils { return; } + node.setPrepared(false); + if (type.writeable()) { node.setSchemtype(type); SchematicSystem.MESSAGE.send("UTIL_TYPE_DONE", player); diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java index a032eb921..8d618600a 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java @@ -309,8 +309,12 @@ public class CheckCommand extends SWCommand { private void concludeCheckSession(String reason, SchematicType type, BooleanSupplier sendMessageIsOnline) { if(SchematicNode.getSchematicNode(schematic.getId()) != null) { CheckedSchematic.create(schematic, checker.user().getId(), startTime, Timestamp.from(Instant.now()), reason, sendMessageIsOnline.getAsBoolean()); - if(type != null) + if(type != null) { schematic.setSchemtype(type); + if (type == SchematicType.Normal) { + schematic.setPrepared(false); + } + } } remove(); From c04e8d75ebe0c8a628c265142ea89d147d7bec2f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 3 Jul 2025 00:57:25 +0200 Subject: [PATCH 107/153] Reorder Colors (again) --- CommonCore/SQL/src/de/steamwar/sql/UserPerm.java | 2 +- .../FightSystem_Core/src/de/steamwar/fightsystem/Config.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java b/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java index 72aebd3a1..af7102653 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java +++ b/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java @@ -58,7 +58,7 @@ public enum UserPerm { p.put(PREFIX_SUPPORTER, new Prefix("§x§1§e§3§a§8§a", "Sup")); // #1e3a8a p.put(PREFIX_MODERATOR, new Prefix("§x§9§2§4§0§0§e", "Mod")); // #92400e p.put(PREFIX_BUILDER, new Prefix("§x§1§5§8§0§3§d", "Arch")); // #15803d - p.put(PREFIX_DEVELOPER, new Prefix("§x§0§7§5§9§8§5", "Dev")); // #075985 + p.put(PREFIX_DEVELOPER, new Prefix("§3", "Dev")); // #075985 p.put(PREFIX_ADMIN, new Prefix("§x§9§9§1§b§1§b", "Admin")); // #991b1b prefixes = Collections.unmodifiableMap(p); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index 11a2a07d1..3ecfa0700 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -367,7 +367,7 @@ public class Config { }else{ //No event TeamRedColor = config.getString("Red.Prefix", "§c"); - TeamBlueColor = config.getString("Blue.Prefix", "§3"); + TeamBlueColor = config.getString("Blue.Prefix", "§9"); TeamRedName = config.getString("Red.Name", "Rot"); TeamBlueName = config.getString("Blue.Name", "Blau"); OnlyPublicSchematics = config.getBoolean("Schematic.OnlyPublicSchematics", false); From 6f64d03feeba0c44fdbf4364d758827e6c746a7b Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 3 Jul 2025 11:07:52 +0200 Subject: [PATCH 108/153] Update pr stuff --- .../bausystem/features/tracer/TraceManager.java | 1 - .../bausystem/features/tracer/TraceRepository.java | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceManager.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceManager.java index 4a741e779..060db33b1 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceManager.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceManager.java @@ -70,7 +70,6 @@ public class TraceManager implements Listener { traceFiles = new File[0]; } - // TODO: Cleanup all traces if a .meta is present! for (File traceFile : traceFiles) { Trace trace = TraceRepository.readTrace(traceFile); if (trace == null) { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRepository.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRepository.java index 3aee95e64..899ea5f13 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRepository.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRepository.java @@ -18,12 +18,12 @@ public class TraceRepository { * Increment this when changing serialisation format */ public static final int SERIALISATION_VERSION = 2; - public static final int WRITE_TICK_DATA = 0x01; - public static final int EXPLOSION = 0x02; - public static final int IN_WATER = 0x04; - public static final int AFTER_FIRST_EXPLOSION = 0x08; - public static final int DESTROYED_BUILD_AREA = 0x10; - public static final int DESTROYED_TEST_BLOCK = 0x20; + public static final int WRITE_TICK_DATA = 0b00000001; + public static final int EXPLOSION = 0b00000010; + public static final int IN_WATER = 0b00000100; + public static final int AFTER_FIRST_EXPLOSION = 0b00001000; + public static final int DESTROYED_BUILD_AREA = 0b00010000; + public static final int DESTROYED_TEST_BLOCK = 0b00100000; public static File tracesFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "traces"); @SneakyThrows From 78584fea3492d4158988220a8a84131c66d5f932 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 3 Jul 2025 16:38:46 +0200 Subject: [PATCH 109/153] Update UserPerm --- CommonCore/SQL/src/de/steamwar/sql/UserPerm.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java b/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java index af7102653..c659ac0d0 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java +++ b/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java @@ -48,18 +48,19 @@ public enum UserPerm { public static final Map prefixes; public static final Prefix emptyPrefix; static { + // https://www.digminecraft.com/lists/color_list_pc.php SqlTypeMapper.nameEnumMapper(UserPerm.class); Map p = new EnumMap<>(UserPerm.class); emptyPrefix = new Prefix("§7", ""); p.put(PREFIX_NONE, emptyPrefix); p.put(PREFIX_YOUTUBER, new Prefix("§7", "YT")); - p.put(PREFIX_GUIDE, new Prefix("§a", "Guide")); + p.put(PREFIX_GUIDE, new Prefix("§a", "Guide")); // 55FF55 - p.put(PREFIX_SUPPORTER, new Prefix("§x§1§e§3§a§8§a", "Sup")); // #1e3a8a - p.put(PREFIX_MODERATOR, new Prefix("§x§9§2§4§0§0§e", "Mod")); // #92400e - p.put(PREFIX_BUILDER, new Prefix("§x§1§5§8§0§3§d", "Arch")); // #15803d - p.put(PREFIX_DEVELOPER, new Prefix("§3", "Dev")); // #075985 - p.put(PREFIX_ADMIN, new Prefix("§x§9§9§1§b§1§b", "Admin")); // #991b1b + p.put(PREFIX_SUPPORTER, new Prefix("§x§3§d§4§8§e§3", "Sup")); // 3D58E3 + p.put(PREFIX_MODERATOR, new Prefix("§x§c§7§5§e§2§2", "Mod")); // C75E22 + p.put(PREFIX_BUILDER, new Prefix("§2", "Arch")); // 00AA00 + p.put(PREFIX_DEVELOPER, new Prefix("§3", "Dev")); // 00AAAA + p.put(PREFIX_ADMIN, new Prefix("§x§F§2§2§8§2§4", "Admin")); // F22824 prefixes = Collections.unmodifiableMap(p); } From 35d8bfb58880568c56ba6bd21474403110c05d2d Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 3 Jul 2025 16:47:58 +0200 Subject: [PATCH 110/153] Update UserPerm Fix Tablist --- CommonCore/SQL/src/de/steamwar/sql/UserPerm.java | 2 +- .../src/de/steamwar/velocitycore/tablist/Tablist.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java b/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java index c659ac0d0..0651dbda2 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java +++ b/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java @@ -56,7 +56,7 @@ public enum UserPerm { p.put(PREFIX_YOUTUBER, new Prefix("§7", "YT")); p.put(PREFIX_GUIDE, new Prefix("§a", "Guide")); // 55FF55 - p.put(PREFIX_SUPPORTER, new Prefix("§x§3§d§4§8§e§3", "Sup")); // 3D58E3 + p.put(PREFIX_SUPPORTER, new Prefix("§x§3§4§0§0§f§f", "Sup")); // 3400ff p.put(PREFIX_MODERATOR, new Prefix("§x§c§7§5§e§2§2", "Mod")); // C75E22 p.put(PREFIX_BUILDER, new Prefix("§2", "Arch")); // 00AA00 p.put(PREFIX_DEVELOPER, new Prefix("§3", "Dev")); // 00AAAA diff --git a/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java b/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java index 8c897e25b..783441a68 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java +++ b/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java @@ -149,8 +149,10 @@ public class Tablist extends ChannelInboundHandlerAdapter { } if (player.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_21_5)) { - // TODO: Misformed Packet? - return; + sendTabPacket(new ArrayList<>(directTabItems.values()), null); + directTabItems.clear(); + sendTabPacket(current, null); + current.clear(); } sendPacket(player, createTeamPacket); From 0091cba336455093c3995045c3bcd090f95c86ae Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 3 Jul 2025 16:59:24 +0200 Subject: [PATCH 111/153] Fix Tablist in 1.21.5 or greater --- VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java b/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java index 783441a68..1447ee3c2 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java +++ b/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java @@ -153,6 +153,8 @@ public class Tablist extends ChannelInboundHandlerAdapter { directTabItems.clear(); sendTabPacket(current, null); current.clear(); + // TODO: Misformed Team Packet? + return; } sendPacket(player, createTeamPacket); From 7a03b327efc2061034d1085c7fe51892f2358df4 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 3 Jul 2025 18:00:17 +0200 Subject: [PATCH 112/153] Fix tablist for real --- .../velocitycore/tablist/Tablist.java | 29 +---- .../tablist/UpdateTeamsPacket21.java | 103 ++++++++++++++++++ 2 files changed, 106 insertions(+), 26 deletions(-) create mode 100644 VelocityCore/src/de/steamwar/velocitycore/tablist/UpdateTeamsPacket21.java diff --git a/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java b/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java index 1447ee3c2..6afb69c7a 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java +++ b/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java @@ -51,7 +51,7 @@ public class Tablist extends ChannelInboundHandlerAdapter { private static final UUID[] swUuids = IntStream.range(0, 80).mapToObj(i -> UUID.randomUUID()).toArray(UUID[]::new); private static final String[] swNames = IntStream.range(0, 80).mapToObj(i -> " »SW« " + String.format("%02d", i)).toArray(String[]::new); - public static final UpdateTeamsPacket createTeamPacket = new UpdateTeamsPacket("zzzzzsw-tab", UpdateTeamsPacket.Mode.CREATE, Component.empty(), Component.empty(), Component.empty(), UpdateTeamsPacket.NameTagVisibility.NEVER, UpdateTeamsPacket.CollisionRule.ALWAYS, 21, (byte)0x00, Arrays.stream(Tablist.swNames).toList()); + public static final UpdateTeamsPacket createTeamPacket = new UpdateTeamsPacket21("zzzzzsw-tab", UpdateTeamsPacket.Mode.CREATE, Component.empty(), Component.empty(), Component.empty(), UpdateTeamsPacket.NameTagVisibility.NEVER, UpdateTeamsPacket.CollisionRule.ALWAYS, 21, (byte)0x00, Arrays.stream(Tablist.swNames).toList()); private final Map directTabItems; private final List current = new ArrayList<>(); @@ -75,26 +75,12 @@ public class Tablist extends ChannelInboundHandlerAdapter { List tablist = new ArrayList<>(); List direct = new ArrayList<>(); global.print(viewer, player, tablist, direct); - - // NPC handling - List update = new ArrayList<>(); - synchronized (directTabItems) { - for (TablistPart.Item item : direct) { - UpsertPlayerInfoPacket.Entry tabItem = directTabItems.get(item.getUuid()); - - if(tabItem == null) { - tablist.add(0, item); - } else if(!item.getDisplayName().equals(getDisplayName(tabItem))) { - tabItem.setDisplayName(new ComponentHolder(player.getProtocolVersion(), item.getDisplayName())); - tabItem.setListed(true); - update.add(tabItem); - } - } - } + tablist.addAll(0, direct); // Main list handling int i = 0; List add = new ArrayList<>(); + List update = new ArrayList<>(); List remove = new ArrayList<>(); for (; i < tablist.size() && i < 80; i++) { TablistPart.Item item = tablist.get(i); @@ -148,15 +134,6 @@ public class Tablist extends ChannelInboundHandlerAdapter { current.clear(); } - if (player.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_21_5)) { - sendTabPacket(new ArrayList<>(directTabItems.values()), null); - directTabItems.clear(); - sendTabPacket(current, null); - current.clear(); - // TODO: Misformed Team Packet? - return; - } - sendPacket(player, createTeamPacket); } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/tablist/UpdateTeamsPacket21.java b/VelocityCore/src/de/steamwar/velocitycore/tablist/UpdateTeamsPacket21.java new file mode 100644 index 000000000..3feab3172 --- /dev/null +++ b/VelocityCore/src/de/steamwar/velocitycore/tablist/UpdateTeamsPacket21.java @@ -0,0 +1,103 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.velocitycore.tablist; + +import com.velocitypowered.api.network.ProtocolVersion; +import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.protocol.packet.UpdateTeamsPacket; +import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder; +import io.netty.buffer.ByteBuf; +import net.kyori.adventure.text.Component; + +import java.util.List; + +public class UpdateTeamsPacket21 extends UpdateTeamsPacket { + + private String name; + private Mode mode; + private Component displayName; + private Component prefix; + private Component suffix; + private NameTagVisibility nameTagVisibility; + private CollisionRule collisionRule; + private int color; + private byte friendlyFlags; + private List players; + + public UpdateTeamsPacket21(String name, Mode mode, Component displayName, Component prefix, Component suffix, NameTagVisibility nameTagVisibility, CollisionRule collisionRule, int color, byte friendlyFlags, List players) { + super(name, mode, displayName, prefix, suffix, nameTagVisibility, collisionRule, color, friendlyFlags, players); + this.name = name; + this.mode = mode; + this.displayName = displayName; + this.prefix = prefix; + this.suffix = suffix; + this.nameTagVisibility = nameTagVisibility; + this.collisionRule = collisionRule; + this.color = color; + this.friendlyFlags = friendlyFlags; + this.players = players; + } + + @Override + public void encode(ByteBuf byteBuf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) { + ProtocolUtils.writeString(byteBuf, this.name); + byteBuf.writeByte(this.mode.ordinal()); + switch (this.mode) { + case CREATE: + case UPDATE: + (new ComponentHolder(protocolVersion, this.displayName)).write(byteBuf); + if (protocolVersion.lessThan(ProtocolVersion.MINECRAFT_1_13)) { + (new ComponentHolder(protocolVersion, this.prefix)).write(byteBuf); + (new ComponentHolder(protocolVersion, this.suffix)).write(byteBuf); + } + + byteBuf.writeByte(this.friendlyFlags); + if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_21_5)) { + ProtocolUtils.writeVarInt(byteBuf, this.nameTagVisibility.ordinal()); + ProtocolUtils.writeVarInt(byteBuf, this.collisionRule.ordinal()); + } else { + ProtocolUtils.writeString(byteBuf, this.nameTagVisibility.getValue()); + ProtocolUtils.writeString(byteBuf, this.collisionRule.getValue()); + } + if (protocolVersion.greaterThan(ProtocolVersion.MINECRAFT_1_12_2)) { + ProtocolUtils.writeVarInt(byteBuf, this.color); + (new ComponentHolder(protocolVersion, this.prefix)).write(byteBuf); + (new ComponentHolder(protocolVersion, this.suffix)).write(byteBuf); + } else { + byteBuf.writeByte((byte)this.color); + } + + ProtocolUtils.writeVarInt(byteBuf, this.players.size()); + + for(String player : this.players) { + ProtocolUtils.writeString(byteBuf, player); + } + break; + case ADD_PLAYER: + case REMOVE_PLAYER: + ProtocolUtils.writeVarInt(byteBuf, this.players.size()); + + for(String player : this.players) { + ProtocolUtils.writeString(byteBuf, player); + } + case REMOVE: + } + } +} From 556c8f7db1bee6c3cf7ef91793e9538bd6fc32bc Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Fri, 4 Jul 2025 17:49:58 +0200 Subject: [PATCH 113/153] Fix MissileWars team colors and TNTLeague team colors --- MissileWars/src/de/steamwar/misslewars/Config.java | 2 +- TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueConfig.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MissileWars/src/de/steamwar/misslewars/Config.java b/MissileWars/src/de/steamwar/misslewars/Config.java index b50ec7410..1838126c0 100644 --- a/MissileWars/src/de/steamwar/misslewars/Config.java +++ b/MissileWars/src/de/steamwar/misslewars/Config.java @@ -158,7 +158,7 @@ public class Config { EventKampf = null; TeamBlueName = "Blau"; TeamRedName = "Rot"; - TeamBlueColor = "§3"; + TeamBlueColor = "§9"; TeamRedColor = "§c"; EventTeamBlueID = 0; EventTeamRedID = 0; diff --git a/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueConfig.kt b/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueConfig.kt index a44fe7d56..861eff6c6 100644 --- a/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueConfig.kt +++ b/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueConfig.kt @@ -63,7 +63,7 @@ data class TNTLeagueConfig( blueTeam = TeamConfig(TNTLeagueWorldConfig.blueTeam, SubMessage("PLAIN_STRING", "§${eventTeamBlue.teamColor}${eventTeamBlue.teamName}"), eventTeamBlue.teamColor[0]) redTeam = TeamConfig(TNTLeagueWorldConfig.redTeam, SubMessage("PLAIN_STRING", "§${eventTeamRed.teamColor}${eventTeamRed.teamName}"), eventTeamRed.teamColor[0]) } else { - blueTeam = TeamConfig(TNTLeagueWorldConfig.blueTeam, SubMessage("BLUE"), '3') + blueTeam = TeamConfig(TNTLeagueWorldConfig.blueTeam, SubMessage("BLUE"), '9') redTeam = TeamConfig(TNTLeagueWorldConfig.redTeam, SubMessage("RED"), 'c') } } From 8c23bf5bd4d7fea75d46d2946376ae58a47c6205 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 6 Jul 2025 11:58:54 +0200 Subject: [PATCH 114/153] Fix 1.21 DisplayEntities --- .../steamwar/entity/PacketConstructor21.java | 34 +++++++++++++++++++ .../de/steamwar/entity/PacketConstructor.java | 29 ++++++++++++++++ .../src/de/steamwar/entity/RBlockDisplay.java | 3 +- .../src/de/steamwar/entity/RDisplay.java | 31 +++++++++-------- .../src/de/steamwar/entity/REntity.java | 4 +++ .../src/de/steamwar/entity/RItemDisplay.java | 5 +-- .../src/de/steamwar/entity/RTextDisplay.java | 9 ++--- 7 files changed, 93 insertions(+), 22 deletions(-) create mode 100644 SpigotCore/SpigotCore_21/src/de/steamwar/entity/PacketConstructor21.java create mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/entity/PacketConstructor.java diff --git a/SpigotCore/SpigotCore_21/src/de/steamwar/entity/PacketConstructor21.java b/SpigotCore/SpigotCore_21/src/de/steamwar/entity/PacketConstructor21.java new file mode 100644 index 000000000..67e501e44 --- /dev/null +++ b/SpigotCore/SpigotCore_21/src/de/steamwar/entity/PacketConstructor21.java @@ -0,0 +1,34 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 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.entity; + +import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; +import net.minecraft.world.entity.PositionMoveRotation; +import net.minecraft.world.phys.Vec3; + +import java.util.Collections; + +public class PacketConstructor21 implements PacketConstructor{ + @Override + public Object teleportPacket(int entityId, double x, double y, double z, float yaw, float pitch) { + PositionMoveRotation rot = new PositionMoveRotation(new Vec3(x, y, z), Vec3.ZERO, pitch, yaw); + return new ClientboundTeleportEntityPacket(entityId, rot, Collections.emptySet(), false); + } +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/PacketConstructor.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/PacketConstructor.java new file mode 100644 index 000000000..6fe49aa89 --- /dev/null +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/PacketConstructor.java @@ -0,0 +1,29 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 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.entity; + +import de.steamwar.core.Core; +import de.steamwar.core.VersionDependent; + +public interface PacketConstructor { + public static final PacketConstructor impl = VersionDependent.getVersionImpl(Core.getInstance()); + + Object teleportPacket(int entityId, double x, double y, double z, float yaw, float pitch); +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java index 5f4c4d509..3a00ae9c8 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java @@ -21,6 +21,7 @@ package de.steamwar.entity; import de.steamwar.Reflection; import de.steamwar.core.BountifulWrapper; +import de.steamwar.core.Core; import lombok.Getter; import org.bukkit.Location; import org.bukkit.Material; @@ -59,7 +60,7 @@ public class RBlockDisplay extends RDisplay { private static final Class iBlockDataClass = Reflection.getClass("net.minecraft.world.level.block.state.BlockState"); private static final Reflection.Method getState = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.block.data.CraftBlockData"), "getState", iBlockDataClass); - private static final Object blockWatcher = BountifulWrapper.impl.getDataWatcherObject(22, iBlockDataClass); + private static final Object blockWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 23 : 22, iBlockDataClass); private void getBlock(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || !block.getAsString(true).equals(DEFAULT_BLOCK.getAsString(true))) { packetSink.accept(blockWatcher, getState.invoke(block)); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java index 863dc6584..d176054df 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java @@ -20,6 +20,7 @@ package de.steamwar.entity; import de.steamwar.core.BountifulWrapper; +import de.steamwar.core.Core; import lombok.Getter; import lombok.NonNull; import org.bukkit.Color; @@ -110,10 +111,10 @@ public abstract class RDisplay extends REntity { sendPacket(updatePacketSink, this::getTransformData); } - private static final Object translationWatcher = BountifulWrapper.impl.getDataWatcherObject(10, Vector3f.class); - private static final Object leftRotationWatcher = BountifulWrapper.impl.getDataWatcherObject(12, Quaternionf.class); - private static final Object scaleWatcher = BountifulWrapper.impl.getDataWatcherObject(11, Vector3f.class); - private static final Object rightRotationWatcher = BountifulWrapper.impl.getDataWatcherObject(13, Quaternionf.class); + private static final Object translationWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 11 : 10, Vector3f.class); + private static final Object leftRotationWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 13 : 12, Quaternionf.class); + private static final Object scaleWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 12 : 11, Vector3f.class); + private static final Object rightRotationWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 14 : 13, Quaternionf.class); private void getTransformData(boolean ignoreDefault, BiConsumer dataSink) { if (ignoreDefault || !transform.equals(DEFAULT_TRANSFORM)) { @@ -129,8 +130,8 @@ public abstract class RDisplay extends REntity { sendPacket(updatePacketSink, this::getInterpolationDuration); } - private static final Object transformationInterpolationDurationWatcher = BountifulWrapper.impl.getDataWatcherObject(8, Integer.class); - private static final Object positionOrRotationInterpolationDurationWatcher = BountifulWrapper.impl.getDataWatcherObject(9, Integer.class); + private static final Object transformationInterpolationDurationWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 9 : 8, Integer.class); + private static final Object positionOrRotationInterpolationDurationWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 10 : 9, Integer.class); private void getInterpolationDuration(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || interpolationDelay != 0) { @@ -144,7 +145,7 @@ public abstract class RDisplay extends REntity { sendPacket(updatePacketSink, this::getViewRange); } - private static final Object viewRangeWatcher = BountifulWrapper.impl.getDataWatcherObject(16, Float.class); + private static final Object viewRangeWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 17 : 16, Float.class); private void getViewRange(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || viewRange != 1.0F) { @@ -157,7 +158,7 @@ public abstract class RDisplay extends REntity { sendPacket(updatePacketSink, this::getShadowRadius); } - private static final Object shadowRadiusWatcher = BountifulWrapper.impl.getDataWatcherObject(17, Float.class); + private static final Object shadowRadiusWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 18 : 17, Float.class); private void getShadowRadius(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || shadowRadius != 0.0F) { @@ -170,7 +171,7 @@ public abstract class RDisplay extends REntity { sendPacket(updatePacketSink, this::getShadowStrength); } - private static final Object shadowStrengthWatcher = BountifulWrapper.impl.getDataWatcherObject(18, Float.class); + private static final Object shadowStrengthWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 19 : 18, Float.class); private void getShadowStrength(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || shadowStrength != 1.0F) { @@ -183,7 +184,7 @@ public abstract class RDisplay extends REntity { sendPacket(updatePacketSink, this::getDisplayWidth); } - private static final Object displayWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(19, Float.class); + private static final Object displayWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 20 : 19, Float.class); private void getDisplayWidth(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || displayWidth != 0.0F) { @@ -196,7 +197,7 @@ public abstract class RDisplay extends REntity { sendPacket(updatePacketSink, this::getDisplayHeight); } - private static final Object displayHeightWatcher = BountifulWrapper.impl.getDataWatcherObject(20, Float.class); + private static final Object displayHeightWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 21 : 20, Float.class); private void getDisplayHeight(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || displayHeight != 0.0F) { @@ -209,7 +210,7 @@ public abstract class RDisplay extends REntity { sendPacket(updatePacketSink, this::getInterpolationDelay); } - private static final Object interpolationDelayWatcher = BountifulWrapper.impl.getDataWatcherObject(7, Integer.class); + private static final Object interpolationDelayWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 8 : 7, Integer.class); private void getInterpolationDelay(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || interpolationDelay != 0) { @@ -222,7 +223,7 @@ public abstract class RDisplay extends REntity { sendPacket(updatePacketSink, this::getBillboard); } - private static final Object billboardWatcher = BountifulWrapper.impl.getDataWatcherObject(14, Byte.class); + private static final Object billboardWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 15 : 14, Byte.class); private void getBillboard(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || billboard != Display.Billboard.FIXED) { @@ -235,7 +236,7 @@ public abstract class RDisplay extends REntity { sendPacket(updatePacketSink, this::getGlowColorOverride); } - private static final Object glowColorOverrideWatcher = BountifulWrapper.impl.getDataWatcherObject(21, Integer.class); + private static final Object glowColorOverrideWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 22 : 21, Integer.class); private void getGlowColorOverride(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || glowColorOverride != null) { @@ -248,7 +249,7 @@ public abstract class RDisplay extends REntity { sendPacket(updatePacketSink, this::getBrightness); } - private static final Object brightnessWatcher = BountifulWrapper.impl.getDataWatcherObject(15, Integer.class); + private static final Object brightnessWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 16 : 15, Integer.class); private void getBrightness(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || brightness != null) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 0c02a8891..a27e6f5e6 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -397,6 +397,10 @@ public class REntity { public static final Reflection.Field teleportEntity = Reflection.getField(teleportPacket, int.class, 0); public static final BountifulWrapper.PositionSetter teleportPosition = BountifulWrapper.impl.getPositionSetter(teleportPacket, Core.getVersion() == 8 ? 1 : 0); private Object getTeleportPacket(){ + if (Core.getVersion() >= 21) { + return PacketConstructor.impl.teleportPacket(entityId, x, y, z, pitch, yaw); + } + Object packet = Reflection.newInstance(teleportPacket); teleportEntity.set(packet, entityId); teleportPosition.set(packet, x, y, z, pitch, yaw); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java index 52cbfc31f..45889637f 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java @@ -20,6 +20,7 @@ package de.steamwar.entity; import de.steamwar.core.BountifulWrapper; +import de.steamwar.core.Core; import de.steamwar.core.ProtocolWrapper; import lombok.Getter; import org.bukkit.Location; @@ -60,14 +61,14 @@ public class RItemDisplay extends RDisplay { sendPacket(updatePacketSink, this::getItemStack); } - private static final Object itemStackWatcher = BountifulWrapper.impl.getDataWatcherObject(22, ProtocolWrapper.itemStack); + private static final Object itemStackWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 23 : 22, ProtocolWrapper.itemStack); private void getItemStack(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || !itemStack.equals(DEFAULT_ITEM_STACK)) { packetSink.accept(itemStackWatcher, asNMSCopy.invoke(null, itemStack)); } } - private static final Object itemDisplayTransformWatcher = BountifulWrapper.impl.getDataWatcherObject(23, Byte.class); + private static final Object itemDisplayTransformWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 24 : 23, Byte.class); public void setItemDisplayTransform(ItemDisplay.ItemDisplayTransform itemDisplayTransform) { this.itemDisplayTransform = itemDisplayTransform; sendPacket(updatePacketSink, this::getItemDisplayTransform); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java index 605b67700..38a10bd6a 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java @@ -22,6 +22,7 @@ package de.steamwar.entity; import de.steamwar.Reflection; import de.steamwar.core.BountifulWrapper; import de.steamwar.core.ChatWrapper; +import de.steamwar.core.Core; import lombok.Getter; import org.bukkit.Location; import org.bukkit.entity.EntityType; @@ -74,7 +75,7 @@ public class RTextDisplay extends RDisplay { } private static final Class iChatBaseComponent = Reflection.getClass("net.minecraft.network.chat.Component"); - private static final Object textWatcher = BountifulWrapper.impl.getDataWatcherObject(22, iChatBaseComponent); + private static final Object textWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 23 : 22, iChatBaseComponent); private void getText(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || !text.isEmpty()) { packetSink.accept(textWatcher, ChatWrapper.impl.stringToChatComponent(text)); @@ -86,7 +87,7 @@ public class RTextDisplay extends RDisplay { sendPacket(updatePacketSink, this::getLineWidth); } - private static final Object lineWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(23, Integer.class); + private static final Object lineWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 24 : 23, Integer.class); private void getLineWidth(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || lineWidth != 200) { packetSink.accept(lineWidthWatcher, lineWidth); @@ -98,7 +99,7 @@ public class RTextDisplay extends RDisplay { sendPacket(updatePacketSink, this::getTextOpacity); } - private static final Object textOpacityWatcher = BountifulWrapper.impl.getDataWatcherObject(25, Byte.class); + private static final Object textOpacityWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 26 : 25, Byte.class); private void getTextOpacity(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || textOpacity != (byte) -1) { packetSink.accept(textOpacityWatcher, textOpacity); @@ -125,7 +126,7 @@ public class RTextDisplay extends RDisplay { sendPacket(updatePacketSink, this::getTextStatus); } - private static final Object textStatusWatcher = BountifulWrapper.impl.getDataWatcherObject(26, Byte.class); + private static final Object textStatusWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 27 : 26, Byte.class); private void getTextStatus(boolean ignoreDefault, BiConsumer packetSink) { byte status = 0; From c1eca74dd05bde45e3fd2452c5bca5227b1cdc34 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 6 Jul 2025 14:06:07 +0200 Subject: [PATCH 115/153] Handle KickedFromServerEvent with redirect and empty component --- .../velocitycore/listeners/ConnectionListener.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java index a6d879c13..d534b29a2 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java @@ -23,6 +23,7 @@ import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.connection.DisconnectEvent; import com.velocitypowered.api.event.connection.PostLoginEvent; import com.velocitypowered.api.event.permission.PermissionsSetupEvent; +import com.velocitypowered.api.event.player.KickedFromServerEvent; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.permission.Tristate; import com.velocitypowered.api.proxy.Player; @@ -38,6 +39,7 @@ import de.steamwar.velocitycore.commands.*; import de.steamwar.velocitycore.discord.DiscordBot; import de.steamwar.velocitycore.discord.util.DiscordRanks; import de.steamwar.velocitycore.mods.ModUtils; +import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.ClickEvent; import java.util.HashSet; @@ -110,6 +112,13 @@ public class ConnectionListener extends BasicListener { } } + @Subscribe + public void kickEvent(KickedFromServerEvent event) { + if (event.getResult() instanceof KickedFromServerEvent.RedirectPlayer red) { + event.setResult(KickedFromServerEvent.RedirectPlayer.create(red.getServer(), Component.empty())); + } + } + @Subscribe public void onDisconnect(DisconnectEvent e){ ChallengeCommand.remove(e.getPlayer()); From 3ae9a41b31bff53561d017d67313f9e302fc7873 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 6 Jul 2025 21:58:05 +0200 Subject: [PATCH 116/153] Hotfix: Entities on 1.21+ --- .../src/de/steamwar/bausystem/utils/NMSWrapper21.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NMSWrapper21.java b/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NMSWrapper21.java index 8d59ffa98..816b9bd74 100644 --- a/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NMSWrapper21.java +++ b/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NMSWrapper21.java @@ -94,7 +94,7 @@ public class NMSWrapper21 implements NMSWrapper { return false; } - return drillDown(data.contents(), 0, 0) <= threshold; + return drillDown(data.contents(), 0, 0) > threshold; } private int drillDown(List items, int layer, int start) { From cccd090357b54bc07c2bbcc5076d3926b06d15a9 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 7 Jul 2025 22:43:16 +0200 Subject: [PATCH 117/153] Add support for TPS and tick rate management in 1.21+ --- .../bausystem/utils/NativeTickManager21.java | 96 ++++++++++++++++++ .../features/tpslimit/TPSSystem.java | 26 ++++- .../modern/ModernTPSLimitCommand.java | 68 +++++++++++++ .../tpslimit/modern/ModernTickCommand.java | 99 +++++++++++++++++++ .../bausystem/utils/NativeTickManager.java | 36 +++++++ 5 files changed, 320 insertions(+), 5 deletions(-) create mode 100644 BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NativeTickManager21.java create mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/modern/ModernTPSLimitCommand.java create mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/modern/ModernTickCommand.java create mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/NativeTickManager.java diff --git a/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NativeTickManager21.java b/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NativeTickManager21.java new file mode 100644 index 000000000..80d9ce175 --- /dev/null +++ b/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NativeTickManager21.java @@ -0,0 +1,96 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 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.utils; + +import com.comphenix.tinyprotocol.TinyProtocol; +import net.minecraft.network.protocol.game.ClientboundTickingStatePacket; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.ServerTickRateManager; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class NativeTickManager21 implements NativeTickManager { + private static final ServerTickRateManager manager = MinecraftServer.getServer().tickRateManager(); + + private boolean blockTpsPacket = true; + + public NativeTickManager21() { + TinyProtocol.instance.addFilter(ClientboundTickingStatePacket.class, this::blockPacket); + } + + private Object blockPacket(Player player, Object packet) { + if (blockTpsPacket) { + return new ClientboundTickingStatePacket(20, manager.isFrozen()); + } else { + return packet; + } + } + + @Override + public void blockTpsPacket(boolean block) { + blockTpsPacket = block; + if (blockTpsPacket) { + ClientboundTickingStatePacket packet = new ClientboundTickingStatePacket(20, manager.isFrozen()); + Bukkit.getOnlinePlayers().forEach(player -> TinyProtocol.instance.sendPacket(player, packet)); + } else { + ClientboundTickingStatePacket packet = new ClientboundTickingStatePacket(manager.tickrate(), manager.isFrozen()); + Bukkit.getOnlinePlayers().forEach(player -> TinyProtocol.instance.sendPacket(player, packet)); + } + } + + @Override + public void setTickRate(float tickRate) { + if (getFreezeState()) { + setFreeze(false); + } + manager.setTickRate(tickRate); + } + + @Override + public boolean getFreezeState() { + return manager.isFrozen(); + } + + @Override + public void setFreeze(boolean freeze) { + manager.setFrozen(freeze); + manager.tick(); + } + + @Override + public void stepTick(int ticks) { + manager.stepGameIfPaused(ticks); + } + + @Override + public void sprintTicks(int ticks) { + manager.requestGameToSprint(ticks, true); + } + + @Override + public boolean isSprinting() { + return manager.isSprinting(); + } + + @Override + public float tickrate() { + return manager.tickrate(); + } +} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java index ac393e57d..46dc72576 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java @@ -25,6 +25,7 @@ import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.linkage.specific.BauGuiItem; import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.NativeTickManager; import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.bausystem.utils.TickEndEvent; import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar; @@ -40,6 +41,7 @@ import de.steamwar.linkage.Linked; import de.steamwar.linkage.LinkedInstance; import de.steamwar.linkage.MaxVersion; import lombok.Getter; +import lombok.Setter; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.boss.BarColor; @@ -52,10 +54,9 @@ import org.bukkit.inventory.ItemStack; import java.util.Arrays; @Linked -@MaxVersion(20) // Hotfix for 1.21 tps limit! -> Backport coming later +@MaxVersion(20) public class TPSSystem implements Listener { - @Getter private static double currentTPSLimit = 20; public TPSSystem() { @@ -66,7 +67,7 @@ public class TPSSystem implements Listener { } new TPSLimitCommand(); new TickLimitCommand(); - if (Core.getVersion() >= 15 && Core.getVersion() <= 20) { // If 1.21 support is not directly present + if (Core.getVersion() >= 15 && Core.getVersion() <= 20) { new TPSWarpCommand(); new TickWarpCommand(); if (TPSFreezeUtils.isCanFreeze()) { @@ -320,7 +321,14 @@ public class TPSSystem implements Listener { @Override public String get(Region region, Player p) { - if (tpsSystem != null && tpsSystem.currentlyStepping) { + boolean isWarping = tpsSystem.currentlyStepping; + boolean isFrozen = TPSFreezeUtils.frozen(); + if (Core.getVersion() >= 21) { + isWarping = NativeTickManager.impl.isSprinting(); + isFrozen = NativeTickManager.impl.getFreezeState(); + } + + if (tpsSystem != null && isWarping) { long time = System.currentTimeMillis() % 1000; if (time < 250) { return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: §7•••"; @@ -331,7 +339,7 @@ public class TPSSystem implements Listener { } else { return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: §7••§e•"; } - } else if (TPSFreezeUtils.frozen()) { + } else if (isFrozen) { return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: " + BauSystem.MESSAGE.parse("SCOREBOARD_TPS_FROZEN", p); } else { return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: " + tpsColor() + TPSWatcher.getTPSUnlimited(TPSWatcher.TPSType.ONE_SECOND) + tpsLimit(); @@ -357,6 +365,14 @@ public class TPSSystem implements Listener { } } + public static double getCurrentTPSLimit() { + if (Core.getVersion() >= 21) { + return NativeTickManager.impl.tickrate(); + } else { + return currentTPSLimit; + } + } + @Linked public static class TPSSystemBauGuiItem extends BauGuiItem { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/modern/ModernTPSLimitCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/modern/ModernTPSLimitCommand.java new file mode 100644 index 000000000..4d2295c0f --- /dev/null +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/modern/ModernTPSLimitCommand.java @@ -0,0 +1,68 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 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.tpslimit.modern; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.utils.NativeTickManager; +import de.steamwar.command.SWCommand; +import de.steamwar.linkage.Linked; +import de.steamwar.linkage.MinVersion; +import org.bukkit.entity.Player; + +import static de.steamwar.bausystem.features.tpslimit.modern.ModernTickCommand.sendTickRateChange; + +@Linked +@MinVersion(21) +public class ModernTPSLimitCommand extends SWCommand { + public ModernTPSLimitCommand() { + super("tpslimit"); + setMessage(BauSystem.MESSAGE); + addDefaultHelpMessage("TPSLIMIT_HELP"); + } + + @Register(value = "0", description = "TPSLIMIT_FREEZE_HELP") + public void freeze(@Validator Player player) { + NativeTickManager.impl.setFreeze(true); + sendTickRateChange(); + } + + @Register(description = "TPSLIMIT_LIMIT_HELP") + public void limit(@Validator Player player, @Min(doubleValue = 0.5) @Max(doubleValue = 20.0) float tpsLimit) { + NativeTickManager.impl.setTickRate(tpsLimit); + sendTickRateChange(); + } + + @Register(description = "TPSLIMIT_WARP_HELP") + public void warp(@Validator Player player, @Min(doubleValue = 20.0, inclusive = false) float tpsLimit) { + NativeTickManager.impl.setTickRate(tpsLimit); + sendTickRateChange(); + } + + @Register(description = "TPSLIMIT_HELP") + public void currentLimit(Player player) { + BauSystem.MESSAGE.send("TPSLIMIT_CURRENT", player, NativeTickManager.impl.tickrate()); + } + + @Register(value = "default", description = "TPSLIMIT_DEFAULT_HELP") + public void reset(@Validator Player player) { + NativeTickManager.impl.setTickRate(20); + sendTickRateChange(); + } +} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/modern/ModernTickCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/modern/ModernTickCommand.java new file mode 100644 index 000000000..057658b53 --- /dev/null +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/modern/ModernTickCommand.java @@ -0,0 +1,99 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 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.tpslimit.modern; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.SWUtils; +import de.steamwar.bausystem.utils.NativeTickManager; +import de.steamwar.command.SWCommand; +import de.steamwar.linkage.Linked; +import de.steamwar.linkage.MinVersion; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; + +@Linked +@MinVersion(21) +public class ModernTickCommand extends SWCommand implements Listener { + public ModernTickCommand() { + super("tick"); + setMessage(BauSystem.MESSAGE); + } + + public static void sendTickRateChange() { + Bukkit.getOnlinePlayers().forEach(player -> { + if (NativeTickManager.impl.getFreezeState()) { + SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("TPSLIMIT_FROZEN", player)); + } else { + SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("TPSLIMIT_SET", player, NativeTickManager.impl.tickrate())); + } + }); + } + + @Register(value = {"rate", "0"}, description = "TICK_FREEZE_HELP") + @Register(value = "freeze", description = "TICK_FREEZE_HELP_2") + public void freeze(@Validator Player player) { + NativeTickManager.impl.setFreeze(true); + sendTickRateChange(); + } + + @Register(value = "unfreeze", description = "TICK_UNFREEZE_HELP") + public void unfreeze(@Validator Player player) { + NativeTickManager.impl.setFreeze(false); + sendTickRateChange(); + } + + @Register(value = "step", description = "TICK_STEPPING_HELP") + public void step(@Validator Player player, @Min(intValue = 1) @OptionalValue("1") int steps) { + NativeTickManager.impl.stepTick(steps); + } + + @Register(value = "warp", description = "TICK_WARP_HELP") + public void warp(@Validator Player player, @Min(intValue = 1) @OptionalValue("1") int steps) { + NativeTickManager.impl.sprintTicks(steps); + } + + @Register(value = "rate", description = "TICK_LIMIT_HELP") + public void limit(@Validator Player player, @Min(doubleValue = 0.5, inclusive = false) float tpsLimit) { + NativeTickManager.impl.setTickRate(tpsLimit); + sendTickRateChange(); + } + + @Register(value = "rate", description = "TICK_HELP") + public void currentLimit(Player player) { + BauSystem.MESSAGE.send("TPSLIMIT_CURRENT", player, NativeTickManager.impl.tickrate()); + } + + @Register(value = {"rate", "default"}, description = "TICK_DEFAULT_HELP") + public void reset(@Validator Player player) { + NativeTickManager.impl.setTickRate(20); + sendTickRateChange(); + } + + @Register(value = "normalclient") + public void smooth(@Validator Player player) { + NativeTickManager.impl.blockTpsPacket(true); + } + + @Register(value = "slowclient") + public void unsmooth(@Validator Player player) { + NativeTickManager.impl.blockTpsPacket(false); + } +} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/NativeTickManager.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/NativeTickManager.java new file mode 100644 index 000000000..7dadf98f6 --- /dev/null +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/NativeTickManager.java @@ -0,0 +1,36 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 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.utils; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.core.VersionDependent; + +public interface NativeTickManager { + NativeTickManager impl = VersionDependent.getVersionImpl(BauSystem.getInstance()); + + void setTickRate(float tickRate); + boolean getFreezeState(); + void setFreeze(boolean freeze); + void stepTick(int ticks); + void sprintTicks(int ticks); + boolean isSprinting(); + float tickrate(); + void blockTpsPacket(boolean block); +} From 3530aec5e293631b83f1287b855ad38f8e1092de Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 8 Jul 2025 10:45:40 +0200 Subject: [PATCH 118/153] Add more Flowers and add Leather horse Armour --- .../schematicsystem/autocheck/AutoCheckerItems15.java | 8 +++++++- .../schematicsystem/autocheck/AutoCheckerItems19.java | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/SchematicSystem/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoCheckerItems15.java b/SchematicSystem/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoCheckerItems15.java index 0d853c16a..ee3f2827c 100644 --- a/SchematicSystem/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoCheckerItems15.java +++ b/SchematicSystem/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoCheckerItems15.java @@ -76,7 +76,13 @@ public class AutoCheckerItems15 implements AutoCheckerItems { Material.DIAMOND_HORSE_ARMOR, Material.IRON_HORSE_ARMOR, Material.GOLDEN_HORSE_ARMOR, - Material.HONEY_BOTTLE); + Material.LEATHER_HORSE_ARMOR, + Material.HONEY_BOTTLE, + Material.LILAC, + Material.ROSE_BUSH, + Material.PEONY, + Material.TALL_GRASS, + Material.LARGE_FERN); @Override public Set getInventoryMaterials() { diff --git a/SchematicSystem/SchematicSystem_19/src/de/steamwar/schematicsystem/autocheck/AutoCheckerItems19.java b/SchematicSystem/SchematicSystem_19/src/de/steamwar/schematicsystem/autocheck/AutoCheckerItems19.java index 0c004cfef..7aaa26b94 100644 --- a/SchematicSystem/SchematicSystem_19/src/de/steamwar/schematicsystem/autocheck/AutoCheckerItems19.java +++ b/SchematicSystem/SchematicSystem_19/src/de/steamwar/schematicsystem/autocheck/AutoCheckerItems19.java @@ -43,12 +43,19 @@ public class AutoCheckerItems19 extends AutoCheckerItems15 { Material.LILY_OF_THE_VALLEY, Material.WITHER_ROSE, Material.SUNFLOWER, + Material.LILAC, + Material.ROSE_BUSH, + Material.PEONY, + Material.TALL_GRASS, + Material.LARGE_FERN, + Material.TORCHFLOWER, // 16-stackable Items Material.HONEY_BOTTLE, // Non-stackable items Material.DIAMOND_HORSE_ARMOR, Material.IRON_HORSE_ARMOR, Material.GOLDEN_HORSE_ARMOR, + Material.LEATHER_HORSE_ARMOR, // Disks Material.MUSIC_DISC_11, Material.MUSIC_DISC_13, From d0414c71f33d0cec4a73687af1270b8631c037d9 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 8 Jul 2025 12:07:03 +0200 Subject: [PATCH 119/153] Fix v3Mode handling in WorldEditWrapper14 --- .../src/de/steamwar/core/WorldEditWrapper14.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java b/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java index 3251e5bcf..b682dad37 100644 --- a/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java +++ b/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java @@ -565,17 +565,17 @@ public class WorldEditWrapper14 implements WorldEditWrapper { for (Map tileEntity : tileEntityTags) { int[] pos = requireTag(tileEntity, "Pos", IntArrayTag.class).getValue(); final BlockVector3 pt = BlockVector3.at(pos[0], pos[1], pos[2]); - Map values = Maps.newHashMap(tileEntity); + Map values = Maps.newHashMap(v3Mode ? requireTag(tileEntity, "Data", CompoundTag.class).getValue() : tileEntity); if(faweSchem){ values.put("x", new IntTag(pt.getBlockX() - offsetX)); values.put("y", new IntTag(pt.getBlockY() - offsetY)); values.put("z", new IntTag(pt.getBlockZ() - offsetZ)); }else{ - values.put("x", new IntTag(pt.getBlockX())); - values.put("y", new IntTag(pt.getBlockY())); - values.put("z", new IntTag(pt.getBlockZ())); + values.putIfAbsent("x", new IntTag(pt.getBlockX())); + values.putIfAbsent("y", new IntTag(pt.getBlockY())); + values.putIfAbsent("z", new IntTag(pt.getBlockZ())); } - values.put("id", values.get("Id")); + values.putIfAbsent("id", values.get("Id")); values.remove("Id"); values.remove("Pos"); if (fixer != null) { From f1c6b4b45319442add1b3813b5e239a9cb3b805c Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Tue, 8 Jul 2025 19:58:49 +0200 Subject: [PATCH 120/153] Update UserPerm colors "final?" --- CommonCore/SQL/src/de/steamwar/sql/UserPerm.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java b/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java index 0651dbda2..50181063d 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java +++ b/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java @@ -54,13 +54,13 @@ public enum UserPerm { emptyPrefix = new Prefix("§7", ""); p.put(PREFIX_NONE, emptyPrefix); p.put(PREFIX_YOUTUBER, new Prefix("§7", "YT")); - p.put(PREFIX_GUIDE, new Prefix("§a", "Guide")); // 55FF55 + p.put(PREFIX_GUIDE, new Prefix("§x§E§5§F§F§8§4", "Guide")); // E5FF84 - p.put(PREFIX_SUPPORTER, new Prefix("§x§3§4§0§0§f§f", "Sup")); // 3400ff - p.put(PREFIX_MODERATOR, new Prefix("§x§c§7§5§e§2§2", "Mod")); // C75E22 - p.put(PREFIX_BUILDER, new Prefix("§2", "Arch")); // 00AA00 - p.put(PREFIX_DEVELOPER, new Prefix("§3", "Dev")); // 00AAAA - p.put(PREFIX_ADMIN, new Prefix("§x§F§2§2§8§2§4", "Admin")); // F22824 + p.put(PREFIX_SUPPORTER, new Prefix("§x§6§0§9§5§F§F", "Sup")); // 6095FF + p.put(PREFIX_MODERATOR, new Prefix("§x§F§F§A§2§5§0", "Mod")); // FFA250 + p.put(PREFIX_BUILDER, new Prefix("§x§6§0§F§F§6§9", "Arch")); // 60FF69 + p.put(PREFIX_DEVELOPER, new Prefix("§x§0§B§B§C§B§9", "Dev")); // 0BBCB9 + p.put(PREFIX_ADMIN, new Prefix("§x§F§F§2§B§2§B", "Admin")); // FF2B2B prefixes = Collections.unmodifiableMap(p); } From a572b840162e6b05e26d8d90fd72452bc4f64d5d Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 8 Jul 2025 21:11:27 +0200 Subject: [PATCH 121/153] Add Items --- .../src/de/steamwar/bausystem/utils/NativeTickManager21.java | 1 - 1 file changed, 1 deletion(-) diff --git a/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NativeTickManager21.java b/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NativeTickManager21.java index 80d9ce175..728870a9d 100644 --- a/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NativeTickManager21.java +++ b/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NativeTickManager21.java @@ -71,7 +71,6 @@ public class NativeTickManager21 implements NativeTickManager { @Override public void setFreeze(boolean freeze) { manager.setFrozen(freeze); - manager.tick(); } @Override From d657f9871d2b6d91399f181e681096158cde390d Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Tue, 8 Jul 2025 22:16:52 +0200 Subject: [PATCH 122/153] Update and integrate legacy system --- .../bausystem/utils/TickManager15.java | 140 ++++++++++++++ .../bausystem/utils/tps}/PacketCache.java | 26 +-- .../bausystem/utils/tps}/TPSFreezeUtils.java | 26 +-- .../bausystem/utils/tps}/TPSLimitUtils.java | 2 +- .../bausystem/utils/TickListener19.java | 3 +- ...eTickManager21.java => TickManager21.java} | 54 +++++- .../src/de/steamwar/bausystem/BauSystem.java | 8 +- .../features/script/lua/libs/TpsLib.java | 3 +- .../features/tpslimit/TPSCommand.java | 24 +-- .../features/tpslimit/TPSSystem.java | 183 ++++++++---------- .../modern/ModernTPSLimitCommand.java | 68 ------- .../tpslimit/modern/ModernTickCommand.java | 99 ---------- ...ativeTickManager.java => TickManager.java} | 20 +- 13 files changed, 333 insertions(+), 323 deletions(-) create mode 100644 BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/TickManager15.java rename BauSystem/{BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit => BauSystem_15/src/de/steamwar/bausystem/utils/tps}/PacketCache.java (83%) rename BauSystem/{BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit => BauSystem_15/src/de/steamwar/bausystem/utils/tps}/TPSFreezeUtils.java (65%) rename BauSystem/{BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit => BauSystem_15/src/de/steamwar/bausystem/utils/tps}/TPSLimitUtils.java (98%) rename BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/{NativeTickManager21.java => TickManager21.java} (67%) delete mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/modern/ModernTPSLimitCommand.java delete mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/modern/ModernTickCommand.java rename BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/{NativeTickManager.java => TickManager.java} (74%) diff --git a/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/TickManager15.java b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/TickManager15.java new file mode 100644 index 000000000..a888e4de5 --- /dev/null +++ b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/TickManager15.java @@ -0,0 +1,140 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.utils; + +import de.steamwar.bausystem.region.GlobalRegion; +import de.steamwar.bausystem.utils.bossbar.BossBarService; +import de.steamwar.bausystem.utils.tps.TPSFreezeUtils; +import de.steamwar.bausystem.utils.tps.TPSLimitUtils; +import de.steamwar.core.TPSWarpUtils; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +public class TickManager15 implements TickManager, Listener { + + private static float currentTPSLimit = 20; + private boolean currentlyStepping = false; + private float currentLimit; + private int stepsTotal; + private int stepsLeft; + + @Override + public boolean canFreeze() { + return TPSFreezeUtils.isCanFreeze(); + } + + @Override + public void setTickRate(float tickRate) { + if (currentlyStepping) { + currentlyStepping = false; + Bukkit.getOnlinePlayers().forEach(player -> { + BossBarService.instance.remove(player, GlobalRegion.getInstance(), "TickStep"); + }); + } + TPSWarpUtils.warp(tickRate); + if (currentTPSLimit == 0 && tickRate != 0) { + TPSFreezeUtils.unfreeze(); + } + currentTPSLimit = tickRate; + if (tickRate == 0) { + TPSLimitUtils.unlimit(); + TPSFreezeUtils.freeze(); + } else if (tickRate < 20.0) { + TPSLimitUtils.limit(tickRate); + } else if (tickRate >= 20) { + TPSLimitUtils.unlimit(); + } + } + + @Override + public boolean isFrozen() { + return TPSFreezeUtils.frozen(); + } + + @Override + public void setFreeze(boolean freeze) { + if (freeze) { + setTickRate(0); + } + } + + @Override + public void stepTicks(int ticks) { + currentLimit = 0; + setTickRate(20); + stepsLeft = ticks; + stepsTotal = ticks; + currentlyStepping = true; + } + + @Override + public void sprintTicks(int ticks) { + currentLimit = currentTPSLimit; + setTickRate(4000); + stepsLeft = ticks; + stepsTotal = ticks; + currentlyStepping = true; + } + + @Override + public boolean isSprinting() { + return currentlyStepping && currentTPSLimit > 20; + } + + @Override + public boolean isStepping() { + return currentlyStepping && currentTPSLimit <= 20; + } + + @Override + public float getTickRate() { + return currentTPSLimit; + } + + @Override + public void blockTpsPacket(boolean block) { + + } + + @Override + public long getTotalTicks() { + return stepsTotal; + } + + @Override + public long getDoneTicks() { + return stepsTotal - stepsLeft; + } + + @Override + public long getRemainingTicks() { + return stepsLeft; + } + + @EventHandler + public void onTickEnd(TickEndEvent event) { + if (!currentlyStepping) return; + stepsLeft--; + if (stepsLeft <= 0) { + setTickRate(currentLimit); + } + } +} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/PacketCache.java b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/tps/PacketCache.java similarity index 83% rename from BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/PacketCache.java rename to BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/tps/PacketCache.java index a53bd8191..63308284f 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/PacketCache.java +++ b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/tps/PacketCache.java @@ -1,23 +1,23 @@ /* - * This file is a part of the SteamWar software. + * This file is a part of the SteamWar software. * - * Copyright (C) 2023 SteamWar.de-Serverteam + * Copyright (C) 2020 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 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. + * 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 . + * 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.tpslimit; +package de.steamwar.bausystem.utils.tps; import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSFreezeUtils.java b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/tps/TPSFreezeUtils.java similarity index 65% rename from BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSFreezeUtils.java rename to BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/tps/TPSFreezeUtils.java index cb79f6fb3..bed7f7e67 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSFreezeUtils.java +++ b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/tps/TPSFreezeUtils.java @@ -1,23 +1,23 @@ /* - * This file is a part of the SteamWar software. + * This file is a part of the SteamWar software. * - * Copyright (C) 2023 SteamWar.de-Serverteam + * Copyright (C) 2020 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 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. + * 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 . + * 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.tpslimit; +package de.steamwar.bausystem.utils.tps; import de.steamwar.Reflection; import lombok.Getter; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/tps/TPSLimitUtils.java similarity index 98% rename from BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java rename to BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/tps/TPSLimitUtils.java index 29068aced..8b58b00a4 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java +++ b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/tps/TPSLimitUtils.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.tpslimit; +package de.steamwar.bausystem.utils.tps; import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; diff --git a/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/TickListener19.java b/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/TickListener19.java index 5191b38ba..211c004ba 100644 --- a/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/TickListener19.java +++ b/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/TickListener19.java @@ -22,7 +22,6 @@ package de.steamwar.bausystem.utils; import com.destroystokyo.paper.event.server.ServerTickEndEvent; import com.destroystokyo.paper.event.server.ServerTickStartEvent; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.tpslimit.TPSFreezeUtils; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -37,7 +36,7 @@ public class TickListener19 implements TickListener, Listener { @EventHandler public void onServerTickStart(ServerTickStartEvent event) { - if (TPSFreezeUtils.isFrozen()) return; + if (TickManager.impl.isFrozen()) return; Bukkit.getPluginManager().callEvent(new TickStartEvent()); tickStartRan = true; } diff --git a/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NativeTickManager21.java b/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/TickManager21.java similarity index 67% rename from BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NativeTickManager21.java rename to BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/TickManager21.java index 728870a9d..fe60c8c43 100644 --- a/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NativeTickManager21.java +++ b/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/TickManager21.java @@ -20,18 +20,23 @@ package de.steamwar.bausystem.utils; import com.comphenix.tinyprotocol.TinyProtocol; +import de.steamwar.Reflection; import net.minecraft.network.protocol.game.ClientboundTickingStatePacket; import net.minecraft.server.MinecraftServer; import net.minecraft.server.ServerTickRateManager; +import net.minecraft.world.TickRateManager; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -public class NativeTickManager21 implements NativeTickManager { +public class TickManager21 implements TickManager { private static final ServerTickRateManager manager = MinecraftServer.getServer().tickRateManager(); + private static final Reflection.Field frozenTicksToRun = Reflection.getField(TickRateManager.class, int.class, 0); + private static final Reflection.Field remainingSprintTicks = Reflection.getField(ServerTickRateManager.class, long.class, 0); private boolean blockTpsPacket = true; + private int totalSteps; - public NativeTickManager21() { + public TickManager21() { TinyProtocol.instance.addFilter(ClientboundTickingStatePacket.class, this::blockPacket); } @@ -43,6 +48,11 @@ public class NativeTickManager21 implements NativeTickManager { } } + @Override + public boolean canFreeze() { + return true; + } + @Override public void blockTpsPacket(boolean block) { blockTpsPacket = block; @@ -57,14 +67,14 @@ public class NativeTickManager21 implements NativeTickManager { @Override public void setTickRate(float tickRate) { - if (getFreezeState()) { + if (isFrozen()) { setFreeze(false); } manager.setTickRate(tickRate); } @Override - public boolean getFreezeState() { + public boolean isFrozen() { return manager.isFrozen(); } @@ -74,12 +84,20 @@ public class NativeTickManager21 implements NativeTickManager { } @Override - public void stepTick(int ticks) { + public void stepTicks(int ticks) { + if (manager.isSprinting()) { + manager.stopSprinting(); + } + this.totalSteps = ticks; manager.stepGameIfPaused(ticks); } @Override public void sprintTicks(int ticks) { + if (manager.isSteppingForward()) { + manager.stopStepping(); + } + this.totalSteps = ticks; manager.requestGameToSprint(ticks, true); } @@ -89,7 +107,31 @@ public class NativeTickManager21 implements NativeTickManager { } @Override - public float tickrate() { + public boolean isStepping() { + return manager.isSteppingForward(); + } + + @Override + public float getTickRate() { return manager.tickrate(); } + + @Override + public long getRemainingTicks() { + if (isSprinting()) { + return remainingSprintTicks.get(manager); + } else { + return frozenTicksToRun.get(manager); + } + } + + @Override + public long getDoneTicks() { + return totalSteps - getRemainingTicks(); + } + + @Override + public long getTotalTicks() { + return totalSteps; + } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 8376f0f19..1d47beb8f 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -19,7 +19,6 @@ package de.steamwar.bausystem; -import de.steamwar.core.WorldEditRendererCUIEditor; import de.steamwar.bausystem.config.BauServer; import de.steamwar.bausystem.configplayer.Config; import de.steamwar.bausystem.configplayer.ConfigConverter; @@ -29,7 +28,6 @@ import de.steamwar.bausystem.features.script.lua.libs.LuaLib; import de.steamwar.bausystem.features.slaves.laufbau.BoundingBoxLoader; import de.steamwar.bausystem.features.slaves.panzern.Panzern; import de.steamwar.bausystem.features.slaves.panzern.PanzernAlgorithm; -import de.steamwar.bausystem.features.tpslimit.TPSFreezeUtils; import de.steamwar.bausystem.features.tracer.TraceManager; import de.steamwar.bausystem.features.tracer.TraceRecorder; import de.steamwar.bausystem.features.world.BauScoreboard; @@ -39,11 +37,13 @@ import de.steamwar.bausystem.region.loader.RegionLoader; import de.steamwar.bausystem.region.loader.Updater; import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.bausystem.utils.TickListener; +import de.steamwar.bausystem.utils.TickManager; import de.steamwar.bausystem.worlddata.WorldData; import de.steamwar.command.AbstractValidator; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; import de.steamwar.core.Core; +import de.steamwar.core.WorldEditRendererCUIEditor; import de.steamwar.linkage.LinkedInstance; import de.steamwar.linkage.MaxVersion; import de.steamwar.linkage.MinVersion; @@ -266,7 +266,7 @@ public class BauSystem extends JavaPlugin { @Override public void run() { - if (TPSFreezeUtils.isFrozen()) return; + if (TickManager.impl.isFrozen()) return; if (counter >= delay) { runnable.run(); cancel(); @@ -284,7 +284,7 @@ public class BauSystem extends JavaPlugin { @Override public void run() { - if (TPSFreezeUtils.isFrozen()) return; + if (TickManager.impl.isFrozen()) return; if (counter >= (first ? delay : period)) { first = false; runnable.run(); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/TpsLib.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/TpsLib.java index 6b9435e1c..44d9a3781 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/TpsLib.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/TpsLib.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.script.lua.libs; import de.steamwar.bausystem.features.tpslimit.TPSSystem; +import de.steamwar.bausystem.utils.TickManager; import de.steamwar.core.TPSWatcher; import de.steamwar.linkage.Linked; import de.steamwar.linkage.LinkedInstance; @@ -51,7 +52,7 @@ public class TpsLib implements LuaLib { tpsLib.set("fiveMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.FIVE_MINUTES))); tpsLib.set("tenMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES))); tpsLib.set("current", getter(TPSWatcher::getTPS)); - tpsLib.set("limit", getter(TPSSystem::getCurrentTPSLimit)); + tpsLib.set("limit", getter(() -> (double) TickManager.impl.getTickRate())); return tpsLib; } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSCommand.java index c1d09c632..f3f4cc620 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSCommand.java @@ -1,20 +1,20 @@ /* - * This file is a part of the SteamWar software. + * This file is a part of the SteamWar software. * - * Copyright (C) 2023 SteamWar.de-Serverteam + * Copyright (C) 2020 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 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. + * 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 . + * 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.tpslimit; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java index 46dc72576..f87c21b38 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java @@ -25,23 +25,19 @@ import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.linkage.specific.BauGuiItem; import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.Region; -import de.steamwar.bausystem.utils.NativeTickManager; import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.bausystem.utils.TickEndEvent; +import de.steamwar.bausystem.utils.TickManager; import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar; import de.steamwar.bausystem.utils.bossbar.BossBarService; import de.steamwar.command.AbstractSWCommand; import de.steamwar.command.SWCommand; import de.steamwar.core.Core; -import de.steamwar.core.TPSWarpUtils; import de.steamwar.core.TPSWatcher; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWItem; import de.steamwar.linkage.Linked; import de.steamwar.linkage.LinkedInstance; -import de.steamwar.linkage.MaxVersion; -import lombok.Getter; -import lombok.Setter; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.boss.BarColor; @@ -54,90 +50,61 @@ import org.bukkit.inventory.ItemStack; import java.util.Arrays; @Linked -@MaxVersion(20) public class TPSSystem implements Listener { - private static double currentTPSLimit = 20; - public TPSSystem() { - if (TPSFreezeUtils.isCanFreeze()) { + if (TickManager.impl.canFreeze()) { new TPSFreezeCommand(); new TickFreezeCommand(); new TickStepCommand(); } new TPSLimitCommand(); new TickLimitCommand(); - if (Core.getVersion() >= 15 && Core.getVersion() <= 20) { + if (Core.getVersion() >= 15) { new TPSWarpCommand(); new TickWarpCommand(); - if (TPSFreezeUtils.isCanFreeze()) { + if (TickManager.impl.canFreeze()) { new TickWarpingCommand(); } } + if (Core.getVersion() >= 21) { + new Tick21Command(); + } new TPSDefaultCommand(); new TickDefaultCommand(); new TPSBaseCommand(); new TickBaseCommand(); - } - - private void setTPS(double tps) { - if (currentlyStepping) { - currentlyStepping = false; - Bukkit.getOnlinePlayers().forEach(player -> { - BossBarService.instance.remove(player, GlobalRegion.getInstance(), "TickStep"); - }); - } - TPSWarpUtils.warp(tps); - if (currentTPSLimit == 0 && tps != 0) { - TPSFreezeUtils.unfreeze(); - } - currentTPSLimit = tps; - if (tps == 0) { - TPSLimitUtils.unlimit(); - TPSFreezeUtils.freeze(); - } else if (tps < 20.0) { - TPSLimitUtils.limit(tps); - } else if (tps >= 20) { - TPSLimitUtils.unlimit(); - } - - Bukkit.getOnlinePlayers().forEach(player -> { - if (currentTPSLimit == 0) { - SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("TPSLIMIT_FROZEN", player)); - } else { - SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("TPSLIMIT_SET", player, currentTPSLimit)); - } - }); - } - - private boolean currentlyStepping = false; - private double currentLimit; - private int stepsTotal; - private int stepsLeft; - - private void setSkip(int steps, double tpsLimitToUse) { - currentLimit = tpsLimitToUse == 20 ? 0 : currentTPSLimit; - setTPS(tpsLimitToUse); - stepsLeft = steps; - stepsTotal = steps; - currentlyStepping = true; + Bukkit.getPluginManager().registerEvents(TickManager.impl, BauSystem.getInstance()); } @EventHandler public void onTickEnd(TickEndEvent event) { - if (!currentlyStepping) return; - if (stepsTotal > 1) { + bossbar(); + } + + private void bossbar() { + if ((TickManager.impl.isStepping() || TickManager.impl.isSprinting()) && TickManager.impl.getRemainingTicks() > 0) { Bukkit.getOnlinePlayers().forEach(player -> { BauSystemBossbar bossbar = BossBarService.instance.get(player, GlobalRegion.getInstance(), "TickStep"); bossbar.setColor(BarColor.YELLOW); - bossbar.setTitle(BauSystem.MESSAGE.parse("TICK_BOSSBAR", player, (stepsTotal - stepsLeft), stepsTotal)); - bossbar.setProgress((stepsTotal - stepsLeft) / (double) stepsTotal); + bossbar.setTitle(BauSystem.MESSAGE.parse("TICK_BOSSBAR", player, TickManager.impl.getDoneTicks(), TickManager.impl.getTotalTicks())); + bossbar.setProgress(TickManager.impl.getDoneTicks() / (double) TickManager.impl.getTotalTicks()); + }); + } else { + Bukkit.getOnlinePlayers().forEach(player -> { + BossBarService.instance.remove(player, GlobalRegion.getInstance(), "TickStep"); }); } - stepsLeft--; - if (stepsLeft <= 0) { - setTPS(currentLimit); - } + } + + public static void sendTickRateChange() { + Bukkit.getOnlinePlayers().forEach(player -> { + if (TickManager.impl.isFrozen()) { + SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("TPSLIMIT_FROZEN", player)); + } else { + SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("TPSLIMIT_SET", player, TickManager.impl.getTickRate())); + } + }); } private class TPSBaseCommand extends SWCommand { @@ -158,7 +125,8 @@ public class TPSSystem implements Listener { @Register(value = "0", description = "TPSLIMIT_FREEZE_HELP") public void freeze(@Validator Player player) { - setTPS(0); + TickManager.impl.setFreeze(true); + sendTickRateChange(); } } @@ -170,8 +138,9 @@ public class TPSSystem implements Listener { } @Register(description = "TPSLIMIT_LIMIT_HELP") - public void limit(@Validator Player player, @Min(doubleValue = 0.5) @Max(doubleValue = 20.0) double tpsLimit) { - setTPS(tpsLimit); + public void limit(@Validator Player player, @Min(doubleValue = 0.5) @Max(doubleValue = 20.0) float tpsLimit) { + TickManager.impl.setTickRate(tpsLimit); + sendTickRateChange(); } } @@ -183,8 +152,9 @@ public class TPSSystem implements Listener { } @Register(description = "TPSLIMIT_WARP_HELP") - public void warp(@Validator Player player, @Min(doubleValue = 20.0, inclusive = false) double tpsLimit) { - setTPS(tpsLimit); + public void warp(@Validator Player player, @Min(doubleValue = 20.0, inclusive = false) float tpsLimit) { + TickManager.impl.setTickRate(tpsLimit); + sendTickRateChange(); } } @@ -197,12 +167,13 @@ public class TPSSystem implements Listener { @Register(description = "TPSLIMIT_HELP") public void currentLimit(Player player) { - BauSystem.MESSAGE.send("TPSLIMIT_CURRENT", player, currentTPSLimit); + BauSystem.MESSAGE.send("TPSLIMIT_CURRENT", player, TickManager.impl.getTickRate()); } @Register(value = "default", description = "TPSLIMIT_DEFAULT_HELP") public void reset(@Validator Player player) { - setTPS(20); + TickManager.impl.setTickRate(20.0F); + sendTickRateChange(); } } @@ -224,12 +195,14 @@ public class TPSSystem implements Listener { @Register(value = {"rate", "0"}, description = "TICK_FREEZE_HELP") @Register(value = "freeze", description = "TICK_FREEZE_HELP_2") public void freeze(@Validator Player player) { - setTPS(0); + TickManager.impl.setFreeze(true); + sendTickRateChange(); } @Register(value = "unfreeze", description = "TICK_UNFREEZE_HELP") public void unfreeze(@Validator Player player) { - setTPS(20); + TickManager.impl.setTickRate(20.0F); + sendTickRateChange(); } } @@ -242,7 +215,9 @@ public class TPSSystem implements Listener { @Register(value = "step", description = "TICK_STEPPING_HELP") public void step(@Validator Player player, @Min(intValue = 1) @OptionalValue("1") int steps) { - setSkip(steps, 20); + TickManager.impl.stepTicks(steps); + sendTickRateChange(); + bossbar(); } } @@ -254,8 +229,9 @@ public class TPSSystem implements Listener { } @Register(value = "warp", description = "TICK_WARPING_HELP") - public void warp(@Validator Player player, @Min(intValue = 1) @OptionalValue("1") int steps, @Min(doubleValue = 20) @OptionalValue("4000") double tps) { - setSkip(steps, tps); + public void warp(@Validator Player player, @Min(intValue = 1) @OptionalValue("1") int steps) { + TickManager.impl.sprintTicks(steps); + sendTickRateChange(); } } @@ -267,8 +243,9 @@ public class TPSSystem implements Listener { } @Register(value = "rate", description = "TICK_LIMIT_HELP") - public void limit(@Validator Player player, @Min(doubleValue = 0.5, inclusive = false) @Max(doubleValue = 20.0) double tpsLimit) { - setTPS(tpsLimit); + public void limit(@Validator Player player, @Min(doubleValue = 0.5, inclusive = false) @Max(doubleValue = 20.0) float tpsLimit) { + TickManager.impl.setTickRate(tpsLimit); + sendTickRateChange(); } } @@ -280,8 +257,9 @@ public class TPSSystem implements Listener { } @Register(value = "rate", description = "TICK_WARP_HELP") - public void warp(@Validator Player player, @Min(doubleValue = 20.0, inclusive = false) double tpsLimit) { - setTPS(tpsLimit); + public void warp(@Validator Player player, @Min(doubleValue = 20.0, inclusive = false) float tpsLimit) { + TickManager.impl.setTickRate(tpsLimit); + sendTickRateChange(); } } @@ -294,12 +272,31 @@ public class TPSSystem implements Listener { @Register(value = "rate", description = "TICK_HELP") public void currentLimit(Player player) { - BauSystem.MESSAGE.send("TPSLIMIT_CURRENT", player, currentTPSLimit); + BauSystem.MESSAGE.send("TPSLIMIT_CURRENT", player, TickManager.impl.getTickRate()); } @Register(value = {"rate", "default"}, description = "TICK_DEFAULT_HELP") public void reset(@Validator Player player) { - setTPS(20); + TickManager.impl.setTickRate(20.0F); + sendTickRateChange(); + } + } + + @AbstractSWCommand.PartOf(TickBaseCommand.class) + private class Tick21Command extends SWCommand { + + private Tick21Command() { + super(""); + } + + @Register(value = "normalclient") + public void smooth(@Validator Player player) { + TickManager.impl.blockTpsPacket(true); + } + + @Register(value = "slowclient") + public void unsmooth(@Validator Player player) { + TickManager.impl.blockTpsPacket(false); } } @@ -321,12 +318,8 @@ public class TPSSystem implements Listener { @Override public String get(Region region, Player p) { - boolean isWarping = tpsSystem.currentlyStepping; - boolean isFrozen = TPSFreezeUtils.frozen(); - if (Core.getVersion() >= 21) { - isWarping = NativeTickManager.impl.isSprinting(); - isFrozen = NativeTickManager.impl.getFreezeState(); - } + boolean isWarping = TickManager.impl.isSprinting(); + boolean isFrozen = TickManager.impl.isFrozen(); if (tpsSystem != null && isWarping) { long time = System.currentTimeMillis() % 1000; @@ -348,28 +341,20 @@ public class TPSSystem implements Listener { private String tpsColor() { double tps = TPSWatcher.getTPSUnlimited(TPSWatcher.TPSType.ONE_SECOND); - if (tps > TPSSystem.getCurrentTPSLimit() * 0.9) { + if (tps > TickManager.impl.getTickRate() * 0.9) { return "§a"; } - if (tps > TPSSystem.getCurrentTPSLimit() * 0.5) { + if (tps > TickManager.impl.getTickRate() * 0.5) { return "§e"; } return "§c"; } private String tpsLimit() { - if (TPSSystem.getCurrentTPSLimit() == 20) { + if (TickManager.impl.getTickRate() == 20) { return ""; } - return "§8/§7" + TPSSystem.getCurrentTPSLimit(); - } - } - - public static double getCurrentTPSLimit() { - if (Core.getVersion() >= 21) { - return NativeTickManager.impl.tickrate(); - } else { - return currentTPSLimit; + return "§8/§7" + TickManager.impl.getTickRate(); } } @@ -385,7 +370,7 @@ public class TPSSystem implements Listener { @Override public ItemStack getItem(Player player) { - return new SWItem(Material.CLOCK, BauSystem.MESSAGE.parse("TPSLIMIT_GUI_ITEM_NAME", player), Arrays.asList(BauSystem.MESSAGE.parse("TPSLIMIT_GUI_ITEM_LORE", player, tpsSystem.currentTPSLimit)), false, clickType -> { + return new SWItem(Material.CLOCK, BauSystem.MESSAGE.parse("TPSLIMIT_GUI_ITEM_NAME", player), Arrays.asList(BauSystem.MESSAGE.parse("TPSLIMIT_GUI_ITEM_LORE", player, TickManager.impl.getTickRate())), false, clickType -> { }).getItemStack(); } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/modern/ModernTPSLimitCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/modern/ModernTPSLimitCommand.java deleted file mode 100644 index 4d2295c0f..000000000 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/modern/ModernTPSLimitCommand.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2025 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.tpslimit.modern; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.utils.NativeTickManager; -import de.steamwar.command.SWCommand; -import de.steamwar.linkage.Linked; -import de.steamwar.linkage.MinVersion; -import org.bukkit.entity.Player; - -import static de.steamwar.bausystem.features.tpslimit.modern.ModernTickCommand.sendTickRateChange; - -@Linked -@MinVersion(21) -public class ModernTPSLimitCommand extends SWCommand { - public ModernTPSLimitCommand() { - super("tpslimit"); - setMessage(BauSystem.MESSAGE); - addDefaultHelpMessage("TPSLIMIT_HELP"); - } - - @Register(value = "0", description = "TPSLIMIT_FREEZE_HELP") - public void freeze(@Validator Player player) { - NativeTickManager.impl.setFreeze(true); - sendTickRateChange(); - } - - @Register(description = "TPSLIMIT_LIMIT_HELP") - public void limit(@Validator Player player, @Min(doubleValue = 0.5) @Max(doubleValue = 20.0) float tpsLimit) { - NativeTickManager.impl.setTickRate(tpsLimit); - sendTickRateChange(); - } - - @Register(description = "TPSLIMIT_WARP_HELP") - public void warp(@Validator Player player, @Min(doubleValue = 20.0, inclusive = false) float tpsLimit) { - NativeTickManager.impl.setTickRate(tpsLimit); - sendTickRateChange(); - } - - @Register(description = "TPSLIMIT_HELP") - public void currentLimit(Player player) { - BauSystem.MESSAGE.send("TPSLIMIT_CURRENT", player, NativeTickManager.impl.tickrate()); - } - - @Register(value = "default", description = "TPSLIMIT_DEFAULT_HELP") - public void reset(@Validator Player player) { - NativeTickManager.impl.setTickRate(20); - sendTickRateChange(); - } -} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/modern/ModernTickCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/modern/ModernTickCommand.java deleted file mode 100644 index 057658b53..000000000 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/modern/ModernTickCommand.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2025 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.tpslimit.modern; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.SWUtils; -import de.steamwar.bausystem.utils.NativeTickManager; -import de.steamwar.command.SWCommand; -import de.steamwar.linkage.Linked; -import de.steamwar.linkage.MinVersion; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.Listener; - -@Linked -@MinVersion(21) -public class ModernTickCommand extends SWCommand implements Listener { - public ModernTickCommand() { - super("tick"); - setMessage(BauSystem.MESSAGE); - } - - public static void sendTickRateChange() { - Bukkit.getOnlinePlayers().forEach(player -> { - if (NativeTickManager.impl.getFreezeState()) { - SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("TPSLIMIT_FROZEN", player)); - } else { - SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("TPSLIMIT_SET", player, NativeTickManager.impl.tickrate())); - } - }); - } - - @Register(value = {"rate", "0"}, description = "TICK_FREEZE_HELP") - @Register(value = "freeze", description = "TICK_FREEZE_HELP_2") - public void freeze(@Validator Player player) { - NativeTickManager.impl.setFreeze(true); - sendTickRateChange(); - } - - @Register(value = "unfreeze", description = "TICK_UNFREEZE_HELP") - public void unfreeze(@Validator Player player) { - NativeTickManager.impl.setFreeze(false); - sendTickRateChange(); - } - - @Register(value = "step", description = "TICK_STEPPING_HELP") - public void step(@Validator Player player, @Min(intValue = 1) @OptionalValue("1") int steps) { - NativeTickManager.impl.stepTick(steps); - } - - @Register(value = "warp", description = "TICK_WARP_HELP") - public void warp(@Validator Player player, @Min(intValue = 1) @OptionalValue("1") int steps) { - NativeTickManager.impl.sprintTicks(steps); - } - - @Register(value = "rate", description = "TICK_LIMIT_HELP") - public void limit(@Validator Player player, @Min(doubleValue = 0.5, inclusive = false) float tpsLimit) { - NativeTickManager.impl.setTickRate(tpsLimit); - sendTickRateChange(); - } - - @Register(value = "rate", description = "TICK_HELP") - public void currentLimit(Player player) { - BauSystem.MESSAGE.send("TPSLIMIT_CURRENT", player, NativeTickManager.impl.tickrate()); - } - - @Register(value = {"rate", "default"}, description = "TICK_DEFAULT_HELP") - public void reset(@Validator Player player) { - NativeTickManager.impl.setTickRate(20); - sendTickRateChange(); - } - - @Register(value = "normalclient") - public void smooth(@Validator Player player) { - NativeTickManager.impl.blockTpsPacket(true); - } - - @Register(value = "slowclient") - public void unsmooth(@Validator Player player) { - NativeTickManager.impl.blockTpsPacket(false); - } -} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/NativeTickManager.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/TickManager.java similarity index 74% rename from BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/NativeTickManager.java rename to BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/TickManager.java index 7dadf98f6..7777c52a7 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/NativeTickManager.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/TickManager.java @@ -21,16 +21,26 @@ package de.steamwar.bausystem.utils; import de.steamwar.bausystem.BauSystem; import de.steamwar.core.VersionDependent; +import org.bukkit.event.Listener; -public interface NativeTickManager { - NativeTickManager impl = VersionDependent.getVersionImpl(BauSystem.getInstance()); +public interface TickManager extends Listener { + TickManager impl = VersionDependent.getVersionImpl(BauSystem.getInstance()); void setTickRate(float tickRate); - boolean getFreezeState(); + float getTickRate(); + + boolean canFreeze(); void setFreeze(boolean freeze); - void stepTick(int ticks); + boolean isFrozen(); + + void stepTicks(int ticks); + boolean isStepping(); + void sprintTicks(int ticks); boolean isSprinting(); - float tickrate(); + void blockTpsPacket(boolean block); + long getRemainingTicks(); + long getDoneTicks(); + long getTotalTicks(); } From 9d6981ee0c5edc04730f34ece9be46363514a7ce Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 10 Jul 2025 10:09:39 +0200 Subject: [PATCH 123/153] Trigger rebuild --- .../src/de/steamwar/bausystem/utils/TickManager15.java | 2 +- .../src/de/steamwar/bausystem/utils/TickManager21.java | 2 +- .../de/steamwar/bausystem/features/tpslimit/TPSSystem.java | 4 ++-- .../src/de/steamwar/bausystem/utils/TickManager.java | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/TickManager15.java b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/TickManager15.java index a888e4de5..a56a2e35d 100644 --- a/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/TickManager15.java +++ b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/TickManager15.java @@ -110,7 +110,7 @@ public class TickManager15 implements TickManager, Listener { } @Override - public void blockTpsPacket(boolean block) { + public void setBlockTpsPacket(boolean block) { } diff --git a/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/TickManager21.java b/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/TickManager21.java index fe60c8c43..a99cb16c6 100644 --- a/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/TickManager21.java +++ b/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/TickManager21.java @@ -54,7 +54,7 @@ public class TickManager21 implements TickManager { } @Override - public void blockTpsPacket(boolean block) { + public void setBlockTpsPacket(boolean block) { blockTpsPacket = block; if (blockTpsPacket) { ClientboundTickingStatePacket packet = new ClientboundTickingStatePacket(20, manager.isFrozen()); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java index f87c21b38..f84ab72ea 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java @@ -291,12 +291,12 @@ public class TPSSystem implements Listener { @Register(value = "normalclient") public void smooth(@Validator Player player) { - TickManager.impl.blockTpsPacket(true); + TickManager.impl.setBlockTpsPacket(true); } @Register(value = "slowclient") public void unsmooth(@Validator Player player) { - TickManager.impl.blockTpsPacket(false); + TickManager.impl.setBlockTpsPacket(false); } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/TickManager.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/TickManager.java index 7777c52a7..6570a03f0 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/TickManager.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/TickManager.java @@ -39,7 +39,7 @@ public interface TickManager extends Listener { void sprintTicks(int ticks); boolean isSprinting(); - void blockTpsPacket(boolean block); + void setBlockTpsPacket(boolean block); long getRemainingTicks(); long getDoneTicks(); long getTotalTicks(); From 2be411839907ea50403fd042714de8b4a2b94b76 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 10 Jul 2025 10:23:28 +0200 Subject: [PATCH 124/153] Close server socket before world saving --- .../src/de/steamwar/core/CheckpointUtilsJ9.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java index e5edcfae4..8df6db806 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java @@ -94,8 +94,6 @@ class CheckpointUtilsJ9 { private static final Reflection.Method bind = Reflection.getMethod(TinyProtocol.serverConnection, null, InetAddress.class, int.class); private static void freezeInternal(Path path) throws Exception { Bukkit.getPluginManager().callEvent(new CRIUSleepEvent()); - Bukkit.getWorlds().forEach(FlatteningWrapper.impl::syncSave); - Statement.closeAll(); // Close socket Object serverConnection = TinyProtocol.getServerConnection(Core.getInstance()); @@ -105,6 +103,9 @@ class CheckpointUtilsJ9 { } channels.clear(); + Bukkit.getWorlds().forEach(FlatteningWrapper.impl::syncSave); + Statement.closeAll(); + System.runFinalization(); System.gc(); From 12f26b982e913cf448b4f40e5a7c26188ae2d7c7 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 10 Jul 2025 10:52:14 +0200 Subject: [PATCH 125/153] Rever CheckpointUtilsJ9 --- .../src/de/steamwar/core/CheckpointUtilsJ9.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java index 8df6db806..2a1894e26 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java @@ -95,6 +95,9 @@ class CheckpointUtilsJ9 { private static void freezeInternal(Path path) throws Exception { Bukkit.getPluginManager().callEvent(new CRIUSleepEvent()); + Bukkit.getWorlds().forEach(FlatteningWrapper.impl::syncSave); + Statement.closeAll(); + // Close socket Object serverConnection = TinyProtocol.getServerConnection(Core.getInstance()); List channels = channelFutures.get(serverConnection); @@ -103,9 +106,6 @@ class CheckpointUtilsJ9 { } channels.clear(); - Bukkit.getWorlds().forEach(FlatteningWrapper.impl::syncSave); - Statement.closeAll(); - System.runFinalization(); System.gc(); From d7908c82550465d9fc1471c675db0806d8a3d310 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 10 Jul 2025 13:02:24 +0200 Subject: [PATCH 126/153] Improve perceived server start time --- .../Persistent/src/de/steamwar/persistent/Subserver.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java b/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java index 9050255e7..832bb9f5b 100644 --- a/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java +++ b/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java @@ -219,8 +219,7 @@ public class Subserver { Exception ex = null; try { if (checkpoint) { - start(process.getErrorStream(), line -> line.contains("Restore finished successfully.")); - Thread.sleep(300); //Wait for port to be reopened + start(process.getErrorStream(), line -> line.contains("Checkpoint restored")); } else { start(process.getInputStream(), line -> { if (line.contains("Loading libraries, please wait")) From a7d64b5887fb38da622c5b82ff87669636afe897 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 10 Jul 2025 13:21:17 +0200 Subject: [PATCH 127/153] Improve TickManager21 --- .../de/steamwar/bausystem/utils/TickManager21.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/TickManager21.java b/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/TickManager21.java index a99cb16c6..af3792f7d 100644 --- a/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/TickManager21.java +++ b/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/TickManager21.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.utils; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.Reflection; +import de.steamwar.bausystem.BauSystem; import net.minecraft.network.protocol.game.ClientboundTickingStatePacket; import net.minecraft.server.MinecraftServer; import net.minecraft.server.ServerTickRateManager; @@ -87,15 +88,27 @@ public class TickManager21 implements TickManager { public void stepTicks(int ticks) { if (manager.isSprinting()) { manager.stopSprinting(); + } else if (manager.isSteppingForward()) { + manager.stopStepping(); } this.totalSteps = ticks; + manager.setFrozen(true); manager.stepGameIfPaused(ticks); + manager.setFrozen(false); + Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), (bukkitTask) -> { + if (manager.isSteppingForward()) return; + manager.setFrozen(true); + bukkitTask.cancel(); + }, 1, 1); + manager.tick(); } @Override public void sprintTicks(int ticks) { if (manager.isSteppingForward()) { manager.stopStepping(); + } else if (manager.isSprinting()) { + manager.stopSprinting(); } this.totalSteps = ticks; manager.requestGameToSprint(ticks, true); From 30ac947ebbb6a9b66f2f3c54ac9dc5c5b3159ce1 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 10 Jul 2025 13:39:03 +0200 Subject: [PATCH 128/153] Add Simulator.autoTestblock --- .../features/simulator/SimulatorCommand.java | 2 +- .../features/simulator/SimulatorCursor.java | 2 +- .../features/simulator/data/Simulator.java | 4 +++- .../simulator/execute/SimulatorExecutor.java | 13 ++++++++++++- .../simulator/execute/SimulatorStabGenerator.java | 4 ++-- .../features/simulator/execute/StabData.java | 2 ++ .../features/simulator/execute/StabStep.java | 2 +- .../simulator/gui/SimulatorSettingsGui.java | 6 +++++- .../features/simulator/gui/SimulatorTNTGui.java | 2 +- .../simulator/storage/SimFormatSimulatorLoader.java | 1 + .../features/simulator/storage/SimulatorSaver.java | 1 + 11 files changed, 30 insertions(+), 9 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java index bf329b3b0..d32d09cce 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java @@ -76,7 +76,7 @@ public class SimulatorCommand extends SWCommand { @Register(value = "start", description = "SIMULATOR_START_HELP") public void start(@Validator Player p, @ErrorMessage("SIMULATOR_NOT_EXISTS") Simulator simulator) { - SimulatorExecutor.run(simulator, () -> {}); + SimulatorExecutor.run(p, simulator, () -> {}); } @Register(value = "rename", description = "SIMULATOR_RENAME_HELP") diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java index f9629c3d9..262701529 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -367,7 +367,7 @@ public class SimulatorCursor implements Listener { if (simulator == null) { return; } - SimulatorExecutor.run(simulator, () -> {}); + SimulatorExecutor.run(event.getPlayer(), simulator, () -> {}); return; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/Simulator.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/Simulator.java index 8dcb83218..5cb4de3cf 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/Simulator.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/Simulator.java @@ -40,9 +40,11 @@ public final class Simulator { private SimulatorStabGenerator stabGenerator = null; private Material material = Material.BARREL; private final String name; - private boolean autoTrace = false; private final List groups = new ArrayList<>(); + private boolean autoTrace = false; + private boolean autoTestblock = false; + public void move(int x, int y, int z) { groups.forEach(simulatorGroup -> { simulatorGroup.move(x, y, z); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorExecutor.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorExecutor.java index b052e4c83..ff343a9e4 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorExecutor.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorExecutor.java @@ -25,17 +25,25 @@ import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.features.tracer.TraceRecorder; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.RegionUtils; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.flagvalues.ColorMode; +import de.steamwar.bausystem.region.utils.RegionExtensionType; +import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.bausystem.utils.PasteBuilder; import de.steamwar.bausystem.utils.TickEndEvent; import de.steamwar.bausystem.utils.TickStartEvent; import de.steamwar.linkage.Linked; import de.steamwar.linkage.MinVersion; import org.bukkit.Bukkit; import org.bukkit.World; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import java.util.*; import java.util.concurrent.atomic.AtomicLong; +import java.util.logging.Level; @Linked @MinVersion(19) @@ -46,7 +54,7 @@ public class SimulatorExecutor implements Listener { private static Map>> tickStartActions = new HashMap<>(); private static Map> tickEndActions = new HashMap<>(); - public static boolean run(Simulator simulator, Runnable onEnd) { + public static boolean run(Player player, Simulator simulator, Runnable onEnd) { if (currentlyRunning.contains(simulator)) return false; currentlyRunning.add(simulator); @@ -87,6 +95,9 @@ public class SimulatorExecutor implements Listener { } }); + if (simulator.isAutoTestblock()) { + player.performCommand("tb"); + } if (simulator.isAutoTrace() && onEnd == null) { simulator.getGroups() .stream() diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorStabGenerator.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorStabGenerator.java index 37ca8bf3d..3263f7724 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorStabGenerator.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorStabGenerator.java @@ -30,8 +30,8 @@ public class SimulatorStabGenerator { private final StabData stabData; - public SimulatorStabGenerator(Region region, Simulator simulator, TNTElement tntElement, int depthLimit) { - stabData = new StabData(region, simulator, tntElement, tntElement.getPhases(), depthLimit); + public SimulatorStabGenerator(Player player, Region region, Simulator simulator, TNTElement tntElement, int depthLimit) { + stabData = new StabData(player, region, simulator, tntElement, tntElement.getPhases(), depthLimit); new StabSetup(stabData); } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/StabData.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/StabData.java index dc1a6e0e9..48c0bc897 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/StabData.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/StabData.java @@ -25,6 +25,7 @@ import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase; import de.steamwar.bausystem.region.Region; import lombok.RequiredArgsConstructor; +import org.bukkit.entity.Player; import java.util.List; import java.util.logging.Level; @@ -38,6 +39,7 @@ public class StabData { protected static final int TNT_INCREASE = 10; protected static final int MIN_BLOCK_TO_COUNT_AS_DEPTH = 20; + protected final Player player; protected final Region region; protected final Simulator simulator; protected final TNTElement tntElement; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/StabStep.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/StabStep.java index ad0d05ee7..9d5bae91a 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/StabStep.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/StabStep.java @@ -58,7 +58,7 @@ public abstract class StabStep { protected abstract void start(); protected final void runSimulator(Runnable onFinish) { - SimulatorExecutor.run(data.simulator, () -> { + SimulatorExecutor.run(data.player, data.simulator, () -> { Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { if (this instanceof Listener) { HandlerList.unregisterAll((Listener) this); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java index 4c442ac41..b69ca41bb 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java @@ -56,10 +56,14 @@ public class SimulatorSettingsGui extends SimulatorBaseGui { })); //AutoTrace - inventory.setItem(20, new SWItem(simulator.isAutoTrace() ? Material.CHAIN_COMMAND_BLOCK : Material.COMMAND_BLOCK, "§eAutoTrace§8: " + (simulator.isAutoTrace() ? "§aOn" : "§cOff"), clickType -> { + inventory.setItem(19, new SWItem(simulator.isAutoTrace() ? Material.CHAIN_COMMAND_BLOCK : Material.COMMAND_BLOCK, "§eAutoTrace§8: " + (simulator.isAutoTrace() ? "§aOn" : "§cOff"), clickType -> { simulator.setAutoTrace(!simulator.isAutoTrace()); SimulatorWatcher.update(simulator); })); + inventory.setItem(20, new SWItem(simulator.isAutoTestblock() ? Material.END_STONE : Material.BARRIER, "§eTestblock§8: " + (simulator.isAutoTestblock() ? "§aOn" : "§cOff"), clickType -> { + simulator.setAutoTestblock(!simulator.isAutoTestblock()); + SimulatorWatcher.update(simulator); + })); //Pos X inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java index 471270c9b..340ae014e 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java @@ -106,7 +106,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui { inventory.setItem(49, new SWItem(Material.CALIBRATED_SCULK_SENSOR, "§eCreate Stab", click -> { new SimulatorAnvilGui<>(player, "Depth Limit", "", Integer::parseInt, depthLimit -> { if (depthLimit <= 0) return false; - simulator.setStabGenerator(new SimulatorStabGenerator(Region.getRegion(player.getLocation()), simulator, tnt, depthLimit)); + simulator.setStabGenerator(new SimulatorStabGenerator(player, Region.getRegion(player.getLocation()), simulator, tnt, depthLimit)); SimulatorWatcher.update(simulator); return true; }, null).open(); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimFormatSimulatorLoader.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimFormatSimulatorLoader.java index 218c89a46..f213227e6 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimFormatSimulatorLoader.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimFormatSimulatorLoader.java @@ -68,6 +68,7 @@ public class SimFormatSimulatorLoader implements SimulatorLoader { private void loadSimulator(YAPIONObject simulatorObject, Simulator simulator) { simulator.setMaterial(Material.valueOf(simulatorObject.getPlainValue("material"))); simulator.setAutoTrace(simulatorObject.getPlainValue("autoTrace")); + simulator.setAutoTestblock(simulatorObject.getPlainValueOrDefault("autoTestblock", false)); YAPIONArray groups = simulatorObject.getArray("groups"); groups.streamObject().forEach(groupObject -> { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimulatorSaver.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimulatorSaver.java index 48ccfd7ab..9a5f52859 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimulatorSaver.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimulatorSaver.java @@ -39,6 +39,7 @@ public class SimulatorSaver { YAPIONObject simulatorObject = new YAPIONObject(); simulatorObject.add("material", simulator.getMaterial().name()); simulatorObject.add("autoTrace", simulator.isAutoTrace()); + simulatorObject.add("autoTestblock", simulator.isAutoTestblock()); YAPIONArray groups = new YAPIONArray(); simulator.getGroups().forEach(group -> { From 71238a0167ba4d7a6599f0d54a07adfcdee9e3e5 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 10 Jul 2025 13:40:21 +0200 Subject: [PATCH 129/153] Add Simulator.autoTestblock --- .../features/simulator/execute/SimulatorExecutor.java | 2 +- .../features/simulator/execute/SimulatorStabGenerator.java | 4 ++-- .../bausystem/features/simulator/execute/StabData.java | 2 -- .../bausystem/features/simulator/execute/StabStep.java | 2 +- .../bausystem/features/simulator/gui/SimulatorTNTGui.java | 2 +- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorExecutor.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorExecutor.java index ff343a9e4..7ca2da8cf 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorExecutor.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorExecutor.java @@ -95,7 +95,7 @@ public class SimulatorExecutor implements Listener { } }); - if (simulator.isAutoTestblock()) { + if (player != null && simulator.isAutoTestblock()) { player.performCommand("tb"); } if (simulator.isAutoTrace() && onEnd == null) { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorStabGenerator.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorStabGenerator.java index 3263f7724..37ca8bf3d 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorStabGenerator.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorStabGenerator.java @@ -30,8 +30,8 @@ public class SimulatorStabGenerator { private final StabData stabData; - public SimulatorStabGenerator(Player player, Region region, Simulator simulator, TNTElement tntElement, int depthLimit) { - stabData = new StabData(player, region, simulator, tntElement, tntElement.getPhases(), depthLimit); + public SimulatorStabGenerator(Region region, Simulator simulator, TNTElement tntElement, int depthLimit) { + stabData = new StabData(region, simulator, tntElement, tntElement.getPhases(), depthLimit); new StabSetup(stabData); } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/StabData.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/StabData.java index 48c0bc897..dc1a6e0e9 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/StabData.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/StabData.java @@ -25,7 +25,6 @@ import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase; import de.steamwar.bausystem.region.Region; import lombok.RequiredArgsConstructor; -import org.bukkit.entity.Player; import java.util.List; import java.util.logging.Level; @@ -39,7 +38,6 @@ public class StabData { protected static final int TNT_INCREASE = 10; protected static final int MIN_BLOCK_TO_COUNT_AS_DEPTH = 20; - protected final Player player; protected final Region region; protected final Simulator simulator; protected final TNTElement tntElement; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/StabStep.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/StabStep.java index 9d5bae91a..6a0e1a2f8 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/StabStep.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/StabStep.java @@ -58,7 +58,7 @@ public abstract class StabStep { protected abstract void start(); protected final void runSimulator(Runnable onFinish) { - SimulatorExecutor.run(data.player, data.simulator, () -> { + SimulatorExecutor.run(null, data.simulator, () -> { Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { if (this instanceof Listener) { HandlerList.unregisterAll((Listener) this); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java index 340ae014e..471270c9b 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java @@ -106,7 +106,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui { inventory.setItem(49, new SWItem(Material.CALIBRATED_SCULK_SENSOR, "§eCreate Stab", click -> { new SimulatorAnvilGui<>(player, "Depth Limit", "", Integer::parseInt, depthLimit -> { if (depthLimit <= 0) return false; - simulator.setStabGenerator(new SimulatorStabGenerator(player, Region.getRegion(player.getLocation()), simulator, tnt, depthLimit)); + simulator.setStabGenerator(new SimulatorStabGenerator(Region.getRegion(player.getLocation()), simulator, tnt, depthLimit)); SimulatorWatcher.update(simulator); return true; }, null).open(); From b86a26a70902f694b1724e9dcfb2c966f7d24d12 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 10 Jul 2025 13:44:06 +0200 Subject: [PATCH 130/153] Fix Simulator.autoTrace --- .../features/simulator/SimulatorCommand.java | 2 +- .../bausystem/features/simulator/SimulatorCursor.java | 2 +- .../features/simulator/execute/SimulatorExecutor.java | 11 +++-------- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java index d32d09cce..646d22a98 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java @@ -76,7 +76,7 @@ public class SimulatorCommand extends SWCommand { @Register(value = "start", description = "SIMULATOR_START_HELP") public void start(@Validator Player p, @ErrorMessage("SIMULATOR_NOT_EXISTS") Simulator simulator) { - SimulatorExecutor.run(p, simulator, () -> {}); + SimulatorExecutor.run(p, simulator, null); } @Register(value = "rename", description = "SIMULATOR_RENAME_HELP") diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java index 262701529..8ffca7a9b 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -367,7 +367,7 @@ public class SimulatorCursor implements Listener { if (simulator == null) { return; } - SimulatorExecutor.run(event.getPlayer(), simulator, () -> {}); + SimulatorExecutor.run(event.getPlayer(), simulator, null); return; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorExecutor.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorExecutor.java index 7ca2da8cf..5192fde80 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorExecutor.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorExecutor.java @@ -25,12 +25,6 @@ import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.features.tracer.TraceRecorder; import de.steamwar.bausystem.region.Region; -import de.steamwar.bausystem.region.RegionUtils; -import de.steamwar.bausystem.region.flags.Flag; -import de.steamwar.bausystem.region.flags.flagvalues.ColorMode; -import de.steamwar.bausystem.region.utils.RegionExtensionType; -import de.steamwar.bausystem.region.utils.RegionType; -import de.steamwar.bausystem.utils.PasteBuilder; import de.steamwar.bausystem.utils.TickEndEvent; import de.steamwar.bausystem.utils.TickStartEvent; import de.steamwar.linkage.Linked; @@ -43,7 +37,6 @@ import org.bukkit.event.Listener; import java.util.*; import java.util.concurrent.atomic.AtomicLong; -import java.util.logging.Level; @Linked @MinVersion(19) @@ -91,7 +84,9 @@ public class SimulatorExecutor implements Listener { }); } - onEnd.run(); + if (onEnd != null) { + onEnd.run(); + } } }); From 868ba4073b10f0cc44047602480b6c8fdeb56c67 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 13 Jul 2025 16:46:11 +0200 Subject: [PATCH 131/153] Add Winconditions.TIMED_DAMAGE_TECH_KO and Winconditions.RANDOM_ROTATE --- .../src/de/steamwar/fightsystem/Config.java | 2 + .../fightsystem/FightSystem.properties | 1 + .../de/steamwar/fightsystem/fight/Fight.java | 9 +- .../fightsystem/fight/FightSchematic.java | 6 + .../fightsystem/record/PacketProcessor.java | 10 +- .../steamwar/fightsystem/record/Recorder.java | 7 ++ .../fightsystem/utils/RandomSeed.java | 45 +++++++ .../winconditions/WinconditionTimeTechKO.java | 11 +- .../WinconditionTimedDamageTechKO.java | 115 ++++++++++++++++++ .../winconditions/Winconditions.java | 4 +- 10 files changed, 196 insertions(+), 14 deletions(-) create mode 100644 FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java create mode 100644 FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimedDamageTechKO.java diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index 3ecfa0700..d7ce5f9e4 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -108,6 +108,7 @@ public class Config { public static final boolean PercentEntern; public static final boolean PercentBlocksWhitelist; public static final Set PercentBlocks; + public static final int TechKoTime; //default kits public static final String MemberDefault; @@ -209,6 +210,7 @@ public class Config { PercentEntern = config.getBoolean("WinConditionParams.PercentEntern", true); PercentBlocksWhitelist = config.getBoolean("WinConditionParams.BlocksWhitelist", false); PercentBlocks = Collections.unmodifiableSet(config.getStringList("WinConditionParams.Blocks").stream().map(Material::valueOf).collect(Collectors.toSet())); + TechKoTime = config.getInt("WinConditionParams.TechKoTime", 90); EnterStages = Collections.unmodifiableList(config.getIntegerList("EnterStages")); AllowMissiles = config.getBoolean("Arena.AllowMissiles", !EnterStages.isEmpty()); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties index 455e0444c..22babff06 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties @@ -191,6 +191,7 @@ BAR_POINTS_OF={0}§8/§7{1} §8Points BAR_PERCENT={0}§8% BAR_CANNONS={0} §8Cannons BAR_WATER={0} §8Water +BAR_SECONDS={0}§8s # Winconditions diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java index 1f2051220..afd357e87 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java @@ -19,20 +19,15 @@ package de.steamwar.fightsystem.fight; -import com.comphenix.tinyprotocol.TinyProtocol; -import com.mojang.authlib.GameProfile; import de.steamwar.core.Core; -import de.steamwar.core.ProtocolWrapper; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.record.GlobalRecorder; +import de.steamwar.fightsystem.utils.RandomSeed; import lombok.Getter; import org.bukkit.Bukkit; -import org.bukkit.GameMode; import org.bukkit.Sound; import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; import java.util.Collection; import java.util.HashSet; @@ -40,6 +35,8 @@ import java.util.HashSet; public class Fight { private Fight(){} + @Getter + private static final RandomSeed randomSeed = new RandomSeed(); @Getter private static final FightTeam redTeam = new FightTeam(Config.TeamRedName, Config.TeamRedColor, Config.TeamRedSpawn, Config.RedPasteRegion, Config.RedExtendRegion, Config.RedRotate, false, Config.RedLeader); @Getter diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index d566c0224..0fe45c73f 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -31,6 +31,7 @@ import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.utils.ColorConverter; import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.utils.WorldeditWrapper; +import de.steamwar.fightsystem.winconditions.Winconditions; import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; @@ -141,6 +142,11 @@ public class FightSchematic extends StateDependent { team.teleportToSpawn(); + boolean rotate = this.rotate; + if (Config.ActiveWinconditions.contains(Winconditions.RANDOM_ROTATE)) { + rotate = Fight.getRandomSeed().getRandom(schematic).nextBoolean(); + } + Vector dims = WorldeditWrapper.impl.getDimensions(clipboard); WorldeditWrapper.impl.pasteClipboard( clipboard, diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index 47efc09df..84906a7b5 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -20,7 +20,6 @@ package de.steamwar.fightsystem.record; import com.sk89q.worldedit.extent.clipboard.Clipboard; -import de.steamwar.core.Core; import de.steamwar.core.TrickyTrialsWrapper; import de.steamwar.core.WorldEditWrapper; import de.steamwar.entity.REntity; @@ -153,6 +152,7 @@ public class PacketProcessor implements Listener { packetDecoder[0xc6] = this::winMessage; packetDecoder[0xc7] = this::bossBarMessage; packetDecoder[0xef] = source::readUTF; + packetDecoder[0xfd] = this::randomSeed; packetDecoder[0xff] = this::tick; execSync(FightWorld::forceLoad); @@ -638,6 +638,14 @@ public class PacketProcessor implements Listener { execSync(() -> entities.get(entityId).setOnFire(perma)); } + private void randomSeed() throws IOException { + long seed = source.readLong(); + + execSync(() -> { + Fight.getRandomSeed().setSeed(seed); + }); + } + private void tick(){ execSync(entityServer::tick); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java index 73821e6fe..c6b899efb 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java @@ -133,6 +133,7 @@ public interface Recorder { * WinPacket (0xc6) + byte team + Message subtitle * BossBarPacket (0xc7) + double leftBlueProgress, leftRedProgress + Message leftBlueText, leftRedText * + * RandomSeed (0xfd) + long seed * CommentPacket (0xfe) + String comment * TickPacket (0xff) * @@ -310,6 +311,10 @@ public interface Recorder { write(0xc6, bTeam, new Message(subtitle, params)); } + default void seed(long seed) { + write(0xfd, seed); + } + default void tick(){ write(0xff); } @@ -339,6 +344,8 @@ public interface Recorder { stream.writeShort((Short)o); else if(o instanceof Integer) stream.writeInt((Integer)o); + else if(o instanceof Long) + stream.writeLong((Long)o); else if(o instanceof Float) stream.writeFloat((Float)o); else if(o instanceof Double) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java new file mode 100644 index 000000000..94db59dd7 --- /dev/null +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java @@ -0,0 +1,45 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.fightsystem.utils; + +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.record.GlobalRecorder; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.OneShotStateDependent; +import lombok.Setter; + +import java.util.Random; + +public class RandomSeed { + + @Setter + private long seed; + + public RandomSeed() { + new OneShotStateDependent(ArenaMode.AntiReplay, FightState.PreSchemSetup, () -> { + this.seed = System.nanoTime(); + GlobalRecorder.getInstance().seed(seed); + }); + } + + public Random getRandom(int derivation) { + return new Random(seed ^ new Random(derivation).nextLong()); + } +} diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java index f1177afa5..df6e92ae4 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java @@ -20,6 +20,7 @@ package de.steamwar.fightsystem.winconditions; import de.steamwar.core.TrickyTrialsWrapper; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.countdown.Countdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; @@ -30,7 +31,6 @@ import de.steamwar.fightsystem.states.StateDependentTask; import de.steamwar.fightsystem.utils.Message; import de.steamwar.fightsystem.utils.SWSound; import org.bukkit.Location; -import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; @@ -41,8 +41,7 @@ import java.util.Map; public class WinconditionTimeTechKO extends Wincondition implements Listener { - private static final int TECH_KO_TIME_IN_S = 90; - private static final int TECH_KO_HALF_TIME = TECH_KO_TIME_IN_S/2; + private static final int TECH_KO_HALF_TIME = Config.TechKoTime/2; private final Map spawnLocations = new HashMap<>(); private final Map countdowns = new HashMap<>(); @@ -51,9 +50,9 @@ public class WinconditionTimeTechKO extends Wincondition implements Listener { public WinconditionTimeTechKO(){ super("TechKO"); - new StateDependentListener(Winconditions.TIME_TECH_KO, FightState.Running, this); - new StateDependentTask(Winconditions.TIME_TECH_KO, FightState.Running, this::run, 20, 20); - new StateDependent(Winconditions.TIME_TECH_KO, FightState.Running) { + new StateDependentListener(Winconditions.TIMED_DAMAGE_TECH_KO, FightState.Running, this); + new StateDependentTask(Winconditions.TIMED_DAMAGE_TECH_KO, FightState.Running, this::run, 20, 20); + new StateDependent(Winconditions.TIMED_DAMAGE_TECH_KO, FightState.Running) { @Override public void enable() { Fight.teams().forEach(team -> currentTime.put(team, TECH_KO_HALF_TIME)); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimedDamageTechKO.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimedDamageTechKO.java new file mode 100644 index 000000000..c561400cc --- /dev/null +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimedDamageTechKO.java @@ -0,0 +1,115 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.fightsystem.winconditions; + +import de.steamwar.core.TrickyTrialsWrapper; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.countdown.Countdown; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; +import de.steamwar.fightsystem.states.StateDependentListener; +import de.steamwar.fightsystem.utils.Message; +import de.steamwar.fightsystem.utils.SWSound; +import org.bukkit.Location; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityExplodeEvent; + +import java.util.HashMap; +import java.util.Map; + +public class WinconditionTimedDamageTechKO extends Wincondition implements PrintableWincondition, Listener { + + private final Map countdowns = new HashMap<>(); + + public WinconditionTimedDamageTechKO() { + super("TechKO"); + + new StateDependentListener(Winconditions.TIMED_DAMAGE_TECH_KO, FightState.Running, this); + new StateDependent(Winconditions.TIMED_DAMAGE_TECH_KO, FightState.Running) { + @Override + public void enable() { + Fight.teams().forEach(team -> { + TechKOCountdown countdown = new TechKOCountdown(team, Config.TechKoTime); + countdowns.put(team, countdown); + countdown.enable(); + }); + } + + @Override + public void disable() { + countdowns.values().forEach(Countdown::disable); + countdowns.clear(); + } + }.register(); + } + + @Override + public Message getDisplay(FightTeam team) { + return new Message("BAR_SECONDS", team.getPrefix() + countdowns.get(team).getTimeLeft()); + } + + @EventHandler + public void onExplode(EntityExplodeEvent e) { + if (e.getEntityType() != TrickyTrialsWrapper.impl.getTntEntityType()) + return; + + Location location = e.getLocation(); + TechKOCountdown countdown = null; + FightTeam fightTeam = null; + for (FightTeam team : Fight.teams()) { + FightTeam current = Fight.getOpposite(team); + if (current.getExtendRegion().inRegion(location)) { + fightTeam = current; + countdown = countdowns.get(team); + break; + } + } + if (fightTeam == null) { + return; + } + + FightTeam finalFightTeam = fightTeam; + TechKOCountdown finalCountdown = countdown; + e.blockList().forEach(block -> { + if (block.isEmpty()) return; + if (finalFightTeam.getExtendRegion().inRegion(block)) { + finalCountdown.disable(); + finalCountdown.enable(); + } + }); + } + + private class TechKOCountdown extends Countdown { + private final FightTeam team; + + public TechKOCountdown(FightTeam team, int countdownTime) { + super(countdownTime, new Message("TECHKO_COUNTDOWN", team.getColoredName()), SWSound.BLOCK_NOTE_PLING, false); + this.team = team; + } + + @Override + public void countdownFinished() { + win(Fight.getOpposite(team), "WIN_TECHKO", team.getColoredName()); + } + } +} diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java index 2aaecae61..81b751736 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java @@ -31,7 +31,8 @@ public enum Winconditions { POINTS, POINTS_AIRSHIP, - TIME_TECH_KO, + DAMAGE_TECH_KO, + TIMED_DAMAGE_TECH_KO, WATER_TECH_KO, PUMPKIN_TECH_KO, @@ -41,4 +42,5 @@ public enum Winconditions { PERSISTENT_DAMAGE, TNT_DISTRIBUTION, NO_GRAVITY, + RANDOM_ROTATE, } From 1e264a63a2d8bf3737081b8fff9c45fc72c127f5 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 13 Jul 2025 16:48:35 +0200 Subject: [PATCH 132/153] Add Winconditions.TIMED_DAMAGE_TECH_KO and Winconditions.RANDOM_ROTATE --- .../fightsystem/winconditions/WinconditionTimeTechKO.java | 6 +++--- .../steamwar/fightsystem/winconditions/Winconditions.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java index df6e92ae4..789b130fa 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java @@ -50,9 +50,9 @@ public class WinconditionTimeTechKO extends Wincondition implements Listener { public WinconditionTimeTechKO(){ super("TechKO"); - new StateDependentListener(Winconditions.TIMED_DAMAGE_TECH_KO, FightState.Running, this); - new StateDependentTask(Winconditions.TIMED_DAMAGE_TECH_KO, FightState.Running, this::run, 20, 20); - new StateDependent(Winconditions.TIMED_DAMAGE_TECH_KO, FightState.Running) { + new StateDependentListener(Winconditions.TIME_TECH_KO, FightState.Running, this); + new StateDependentTask(Winconditions.TIME_TECH_KO, FightState.Running, this::run, 20, 20); + new StateDependent(Winconditions.TIME_TECH_KO, FightState.Running) { @Override public void enable() { Fight.teams().forEach(team -> currentTime.put(team, TECH_KO_HALF_TIME)); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java index 81b751736..4ba66cf3d 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java @@ -31,8 +31,8 @@ public enum Winconditions { POINTS, POINTS_AIRSHIP, - DAMAGE_TECH_KO, TIMED_DAMAGE_TECH_KO, + TIME_TECH_KO, WATER_TECH_KO, PUMPKIN_TECH_KO, From e9d107f0ed5331fbb77cb04ba15f73ac31ef703b Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 13 Jul 2025 17:54:06 +0200 Subject: [PATCH 133/153] Fix older replays --- .../de/steamwar/fightsystem/fight/FightSchematic.java | 2 +- .../src/de/steamwar/fightsystem/utils/RandomSeed.java | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index 0fe45c73f..7c7b6e81a 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -143,7 +143,7 @@ public class FightSchematic extends StateDependent { team.teleportToSpawn(); boolean rotate = this.rotate; - if (Config.ActiveWinconditions.contains(Winconditions.RANDOM_ROTATE)) { + if (Fight.getRandomSeed().isInitialized() && Config.ActiveWinconditions.contains(Winconditions.RANDOM_ROTATE)) { rotate = Fight.getRandomSeed().getRandom(schematic).nextBoolean(); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java index 94db59dd7..49ac1cd4e 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java @@ -23,13 +23,14 @@ import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.OneShotStateDependent; -import lombok.Setter; +import lombok.Getter; import java.util.Random; public class RandomSeed { - @Setter + @Getter + private boolean initialized = false; private long seed; public RandomSeed() { @@ -39,6 +40,11 @@ public class RandomSeed { }); } + public void setSeed(long seed) { + initialized = true; + this.seed = seed; + } + public Random getRandom(int derivation) { return new Random(seed ^ new Random(derivation).nextLong()); } From b9b541957b3609fd3258267936bc98fea405ca11 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 13 Jul 2025 17:54:28 +0200 Subject: [PATCH 134/153] Fix older replays --- .../src/de/steamwar/fightsystem/utils/RandomSeed.java | 1 + 1 file changed, 1 insertion(+) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java index 49ac1cd4e..397afcc8a 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java @@ -35,6 +35,7 @@ public class RandomSeed { public RandomSeed() { new OneShotStateDependent(ArenaMode.AntiReplay, FightState.PreSchemSetup, () -> { + initialized = true; this.seed = System.nanoTime(); GlobalRecorder.getInstance().seed(seed); }); From 167b36b10cbb60674d045e22882d2cd29e232587 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 13 Jul 2025 18:10:53 +0200 Subject: [PATCH 135/153] Update RandomRotate --- .../fightsystem/fight/FightSchematic.java | 19 +++---- .../steamwar/fightsystem/fight/FightTeam.java | 8 +++ .../fightsystem/record/PacketProcessor.java | 10 ++++ .../steamwar/fightsystem/record/Recorder.java | 21 ++++---- .../fightsystem/utils/RandomSeed.java | 52 ------------------- 5 files changed, 40 insertions(+), 70 deletions(-) delete mode 100644 FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index 7c7b6e81a..aaffe4c42 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -36,6 +36,7 @@ import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; import lombok.Getter; +import lombok.Setter; import org.bukkit.Bukkit; import org.bukkit.DyeColor; import org.bukkit.Location; @@ -52,7 +53,10 @@ public class FightSchematic extends StateDependent { private final FightTeam team; private final Region region; - private final boolean rotate; + + @Getter + @Setter + private boolean rotate; @Getter private Clipboard clipboard = null; @@ -120,10 +124,13 @@ public class FightSchematic extends StateDependent { } if(ArenaMode.AntiReplay.contains(Config.mode)) { + if (Config.ActiveWinconditions.contains(Winconditions.RANDOM_ROTATE)) { + rotate = new Random().nextBoolean(); + } if(team.isBlue()) - GlobalRecorder.getInstance().blueSchem(schematic); + GlobalRecorder.getInstance().blueSchem(schematic, rotate); else - GlobalRecorder.getInstance().redSchem(schematic); + GlobalRecorder.getInstance().redSchem(schematic, rotate); } Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::paste); @@ -141,12 +148,6 @@ public class FightSchematic extends StateDependent { FreezeWorld freezer = new FreezeWorld(); team.teleportToSpawn(); - - boolean rotate = this.rotate; - if (Fight.getRandomSeed().isInitialized() && Config.ActiveWinconditions.contains(Winconditions.RANDOM_ROTATE)) { - rotate = Fight.getRandomSeed().getRandom(schematic).nextBoolean(); - } - Vector dims = WorldeditWrapper.impl.getDimensions(clipboard); WorldeditWrapper.impl.pasteClipboard( clipboard, diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 0cb68f719..319f2dbb0 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -458,6 +458,14 @@ public class FightTeam { return schematic.getId(); } + public boolean getSchematicRotate() { + return schematic.isRotate(); + } + + public void setSchematicRotate(boolean rotate) { + schematic.setRotate(rotate); + } + public Clipboard getClipboard() { return schematic.getClipboard(); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index 84906a7b5..2cc846886 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -143,6 +143,8 @@ public class PacketProcessor implements Listener { packetDecoder[0xb2] = this::teams; packetDecoder[0xb3] = () -> pasteEmbeddedSchem(Fight.getBlueTeam()); packetDecoder[0xb4] = () -> pasteEmbeddedSchem(Fight.getRedTeam()); + packetDecoder[0xb5] = () -> rotateSchem(Fight.getBlueTeam()); + packetDecoder[0xb6] = () -> rotateSchem(Fight.getRedTeam()); packetDecoder[0xc0] = this::scoreboardTitle; packetDecoder[0xc1] = this::scoreboardData; packetDecoder[0xc2] = this::bossBar; @@ -529,6 +531,14 @@ public class PacketProcessor implements Listener { execSync(() -> team.pasteSchem(schemId, clipboard)); } + private void rotateSchem(FightTeam team) throws IOException { + boolean rotate = source.readBoolean(); + + execSync(() -> { + team.setSchematicRotate(rotate); + }); + } + private void teams() throws IOException { int blueId = source.readInt(); int redId = source.readInt(); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java index c6b899efb..cf8005656 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java @@ -61,9 +61,9 @@ public interface Recorder { default void enableTeam(FightTeam team){ if(FightState.Schem.contains(FightState.getFightState())){ if(team.isBlue()) - blueSchem(team.getSchematic()); + blueSchem(team.getSchematic(), team.getSchematicRotate()); else - redSchem(team.getSchematic()); + redSchem(team.getSchematic(), team.getSchematicRotate()); } if(FightState.AntiSpectate.contains(FightState.getFightState())){ @@ -123,6 +123,8 @@ public interface Recorder { * TeamIDPacket (0xb2) + int blueTeamId, redTeamId * BlueEmbeddedSchemPacket (0xb3) + int blueSchemId + gzipt NBT blob * RedEmbeddedSchemPacket (0xb4) + int redSchemId + gzipt NBT blob + * BlueSchemRotatePacket (0xb5) + boolean rotate + * RedSchemRotatePacket (0xb6) + boolean rotate * * DEPRECATED ScoreboardTitlePacket (0xc0) + String scoreboardTitle * DEPRECATED ScoreboardDataPacket (0xc1) + String key + int value @@ -133,7 +135,6 @@ public interface Recorder { * WinPacket (0xc6) + byte team + Message subtitle * BossBarPacket (0xc7) + double leftBlueProgress, leftRedProgress + Message leftBlueText, leftRedText * - * RandomSeed (0xfd) + long seed * CommentPacket (0xfe) + String comment * TickPacket (0xff) * @@ -260,14 +261,20 @@ public interface Recorder { write(0xb2, blueTeamId, redTeamId); } - default void blueSchem(int schemId) { + default void blueSchem(int schemId, boolean rotate) { + rotate(0xb5, rotate); schem(0xb3, 0xb0, schemId); } - default void redSchem(int schemId) { + default void redSchem(int schemId, boolean rotate) { + rotate(0xb6, rotate); schem(0xb4, 0xb1, schemId); } + default void rotate(int packetId, boolean rotate) { + write(packetId, rotate); + } + default void schem(int embedId, int noEmbedId, int schemId){ if(schemId == 0) { write(noEmbedId, schemId); @@ -311,10 +318,6 @@ public interface Recorder { write(0xc6, bTeam, new Message(subtitle, params)); } - default void seed(long seed) { - write(0xfd, seed); - } - default void tick(){ write(0xff); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java deleted file mode 100644 index 397afcc8a..000000000 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 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.fightsystem.utils; - -import de.steamwar.fightsystem.ArenaMode; -import de.steamwar.fightsystem.record.GlobalRecorder; -import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.OneShotStateDependent; -import lombok.Getter; - -import java.util.Random; - -public class RandomSeed { - - @Getter - private boolean initialized = false; - private long seed; - - public RandomSeed() { - new OneShotStateDependent(ArenaMode.AntiReplay, FightState.PreSchemSetup, () -> { - initialized = true; - this.seed = System.nanoTime(); - GlobalRecorder.getInstance().seed(seed); - }); - } - - public void setSeed(long seed) { - initialized = true; - this.seed = seed; - } - - public Random getRandom(int derivation) { - return new Random(seed ^ new Random(derivation).nextLong()); - } -} From f7662cdcba14db42a6ec3acace2fc9e8635245cc Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 13 Jul 2025 18:15:24 +0200 Subject: [PATCH 136/153] Fix build --- .../src/de/steamwar/fightsystem/fight/Fight.java | 3 --- .../de/steamwar/fightsystem/record/PacketProcessor.java | 9 --------- 2 files changed, 12 deletions(-) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java index afd357e87..61f6a1622 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java @@ -23,7 +23,6 @@ import de.steamwar.core.Core; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.record.GlobalRecorder; -import de.steamwar.fightsystem.utils.RandomSeed; import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.Sound; @@ -35,8 +34,6 @@ import java.util.HashSet; public class Fight { private Fight(){} - @Getter - private static final RandomSeed randomSeed = new RandomSeed(); @Getter private static final FightTeam redTeam = new FightTeam(Config.TeamRedName, Config.TeamRedColor, Config.TeamRedSpawn, Config.RedPasteRegion, Config.RedExtendRegion, Config.RedRotate, false, Config.RedLeader); @Getter diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index 2cc846886..22b675b48 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -154,7 +154,6 @@ public class PacketProcessor implements Listener { packetDecoder[0xc6] = this::winMessage; packetDecoder[0xc7] = this::bossBarMessage; packetDecoder[0xef] = source::readUTF; - packetDecoder[0xfd] = this::randomSeed; packetDecoder[0xff] = this::tick; execSync(FightWorld::forceLoad); @@ -648,14 +647,6 @@ public class PacketProcessor implements Listener { execSync(() -> entities.get(entityId).setOnFire(perma)); } - private void randomSeed() throws IOException { - long seed = source.readLong(); - - execSync(() -> { - Fight.getRandomSeed().setSeed(seed); - }); - } - private void tick(){ execSync(entityServer::tick); From 104f0cf02da06a1b1238dce052dbf9d21722dfe6 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 13 Jul 2025 18:39:53 +0200 Subject: [PATCH 137/153] Fix final stuff --- .../de/steamwar/fightsystem/FightSystem.java | 1 + .../fightsystem/fight/FightSchematic.java | 26 ++++++++++++------- .../steamwar/fightsystem/fight/FightTeam.java | 8 ++---- .../fightsystem/record/PacketProcessor.java | 4 +-- .../steamwar/fightsystem/record/Recorder.java | 20 +++++++------- 5 files changed, 31 insertions(+), 28 deletions(-) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 9ebc4f0c9..d181ce02d 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -126,6 +126,7 @@ public class FightSystem extends JavaPlugin { new WinconditionPointsAirShip(); new WinconditionTimeout(); new WinconditionTimeTechKO(); + new WinconditionTimedDamageTechKO(); new EventTeamOffWincondition(); new WinconditionComparisonTimeout(Winconditions.HEART_RATIO_TIMEOUT, "HeartTimeout", "WIN_MORE_HEALTH", FightTeam::getHeartRatio); new WinconditionComparisonTimeout(Winconditions.PERCENT_TIMEOUT, "PercentTimeout", "WIN_LESS_DAMAGE", team -> -Wincondition.getPercentWincondition().getPercent(team)); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index aaffe4c42..63395d034 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -36,7 +36,6 @@ import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; import lombok.Getter; -import lombok.Setter; import org.bukkit.Bukkit; import org.bukkit.DyeColor; import org.bukkit.Location; @@ -54,22 +53,27 @@ public class FightSchematic extends StateDependent { private final FightTeam team; private final Region region; + private final boolean rotate; @Getter - @Setter - private boolean rotate; + private boolean usedRotate; @Getter private Clipboard clipboard = null; private int schematic = 0; - public FightSchematic(FightTeam team, boolean rotate) { + public FightSchematic(FightTeam team, boolean usedRotate) { super(ArenaMode.All, FightState.PostSchemSetup); this.team = team; this.region = team.getSchemRegion(); - this.rotate = rotate; + this.rotate = usedRotate; + this.usedRotate = usedRotate; register(); } + public void setChangeRotate(boolean rotate) { + this.usedRotate = this.rotate ^ rotate; + } + public boolean hasSchematic() { return clipboard != null; } @@ -124,13 +128,15 @@ public class FightSchematic extends StateDependent { } if(ArenaMode.AntiReplay.contains(Config.mode)) { + boolean changeRotation = false; if (Config.ActiveWinconditions.contains(Winconditions.RANDOM_ROTATE)) { - rotate = new Random().nextBoolean(); + changeRotation = new Random().nextBoolean(); + usedRotate = rotate ^ changeRotation; } if(team.isBlue()) - GlobalRecorder.getInstance().blueSchem(schematic, rotate); + GlobalRecorder.getInstance().blueSchem(schematic, changeRotation); else - GlobalRecorder.getInstance().redSchem(schematic, rotate); + GlobalRecorder.getInstance().redSchem(schematic, changeRotation); } Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::paste); @@ -156,8 +162,8 @@ public class FightSchematic extends StateDependent { Config.PasteAligned && Config.BlueToRedX != 0 ? region.getSizeX()/2.0 - dims.getBlockX() : -dims.getBlockX()/2.0, Config.WaterDepth != 0 ? Config.WaterDepth - WorldeditWrapper.impl.getWaterDepth(clipboard) : 0, Config.PasteAligned && Config.BlueToRedZ != 0 ? region.getSizeZ()/2.0 - dims.getBlockZ() : -dims.getBlockZ()/2.0 - ).add(new Vector(rotate ? 1 : 0, 0, rotate ? 1 : 0)), - new AffineTransform().rotateY(rotate ? 180 : 0) + ).add(new Vector(usedRotate ? 1 : 0, 0, usedRotate ? 1 : 0)), + new AffineTransform().rotateY(usedRotate ? 180 : 0) ); FightSystem.getHullHider().initialize(team); team.getPlayers().forEach(fightPlayer -> fightPlayer.ifAI(ai -> ai.schematic(clipboard))); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 319f2dbb0..6c9c0345e 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -458,12 +458,8 @@ public class FightTeam { return schematic.getId(); } - public boolean getSchematicRotate() { - return schematic.isRotate(); - } - - public void setSchematicRotate(boolean rotate) { - schematic.setRotate(rotate); + public void setSchematicChangeRotate(boolean rotate) { + schematic.setChangeRotate(rotate); } public Clipboard getClipboard() { diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index 22b675b48..f4906f42f 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -531,10 +531,10 @@ public class PacketProcessor implements Listener { } private void rotateSchem(FightTeam team) throws IOException { - boolean rotate = source.readBoolean(); + boolean changeRotate = source.readBoolean(); execSync(() -> { - team.setSchematicRotate(rotate); + team.setSchematicChangeRotate(changeRotate); }); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java index cf8005656..8b1596605 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java @@ -61,9 +61,9 @@ public interface Recorder { default void enableTeam(FightTeam team){ if(FightState.Schem.contains(FightState.getFightState())){ if(team.isBlue()) - blueSchem(team.getSchematic(), team.getSchematicRotate()); + blueSchem(team.getSchematic(), false); else - redSchem(team.getSchematic(), team.getSchematicRotate()); + redSchem(team.getSchematic(), false); } if(FightState.AntiSpectate.contains(FightState.getFightState())){ @@ -123,8 +123,8 @@ public interface Recorder { * TeamIDPacket (0xb2) + int blueTeamId, redTeamId * BlueEmbeddedSchemPacket (0xb3) + int blueSchemId + gzipt NBT blob * RedEmbeddedSchemPacket (0xb4) + int redSchemId + gzipt NBT blob - * BlueSchemRotatePacket (0xb5) + boolean rotate - * RedSchemRotatePacket (0xb6) + boolean rotate + * BlueSchemRotatePacket (0xb5) + boolean changeRotate + * RedSchemRotatePacket (0xb6) + boolean changeRotate * * DEPRECATED ScoreboardTitlePacket (0xc0) + String scoreboardTitle * DEPRECATED ScoreboardDataPacket (0xc1) + String key + int value @@ -261,18 +261,18 @@ public interface Recorder { write(0xb2, blueTeamId, redTeamId); } - default void blueSchem(int schemId, boolean rotate) { - rotate(0xb5, rotate); + default void blueSchem(int schemId, boolean changeRotate) { + rotate(0xb5, changeRotate); schem(0xb3, 0xb0, schemId); } - default void redSchem(int schemId, boolean rotate) { - rotate(0xb6, rotate); + default void redSchem(int schemId, boolean changeRotate) { + rotate(0xb6, changeRotate); schem(0xb4, 0xb1, schemId); } - default void rotate(int packetId, boolean rotate) { - write(packetId, rotate); + default void rotate(int packetId, boolean changeRotate) { + write(packetId, changeRotate); } default void schem(int embedId, int noEmbedId, int schemId){ From 0e9c9bd4dc734b61eb92dd17a69a011c086d089d Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 13 Jul 2025 20:48:43 +0200 Subject: [PATCH 138/153] Hotfix DiscordChannel --- .../velocitycore/discord/channels/DiscordChannel.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java index 5fcbcf6a2..49b5d4f20 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java @@ -85,9 +85,9 @@ public class DiscordChannel extends Chatter.PlayerlessChatter { public void send(String message) { message = message .replace("&", "") - .replace("@everyone", "`@everyone`") - .replace("@here", "`@here`") - .replaceAll("<[@#]!?\\d+>", "`$0`"); + .replace("@everyone", "@\u200Beveryone") + .replace("@here", "@\u200Bhere") + .replaceAll("<([@#])(!?\\d+)>", "<$1\u200B$2>"); if (maxNumberOfWebhooks > 0 && getChannel() instanceof TextChannel && message.contains("»")) { String[] strings = message.split("»", 2); From dc72ec1b93163c477f37fb8b75f67dedc4ecd4d6 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 13 Jul 2025 20:57:22 +0200 Subject: [PATCH 139/153] Hotfix REntityServer for 1.15 or earlier --- .../SpigotCore_Main/src/de/steamwar/entity/REntityServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index 119507aab..2a9a2a13f 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -50,11 +50,11 @@ public class REntityServer implements Listener { private static final Class useEntity = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket"); private static final Reflection.Field useEntityTarget = Reflection.getField(useEntity, int.class, 0); private static final Class useEntityEnumAction = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket$Action"); - private static final Class useEntityEnumActionType = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket$ActionType"); private static final Reflection.Field useEntityAction = Reflection.getField(useEntity, useEntityEnumAction, 0); private static final Function getEntityAction; static { if(Core.getVersion() > 15) { + Class useEntityEnumActionType = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket$ActionType"); Reflection.Method useEntityGetAction = Reflection.getTypedMethod(useEntityEnumAction, null, useEntityEnumActionType); getEntityAction = value -> ((Enum) useEntityGetAction.invoke(value)).ordinal(); } else { From f33b3521b8b6cb616332ae77abf6973fc0cbc8f9 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 13 Jul 2025 21:00:42 +0200 Subject: [PATCH 140/153] Hotfix TNTPoint for 1.15 or earlier --- .../steamwar/bausystem/features/tracer/TNTPoint.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TNTPoint.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TNTPoint.java index 1e9fd38da..a33c52f09 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TNTPoint.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TNTPoint.java @@ -22,19 +22,15 @@ package de.steamwar.bausystem.features.tracer; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.core.Core; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.TNTPrimed; import org.bukkit.util.Vector; -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; import java.util.List; import java.util.Optional; @@ -106,7 +102,11 @@ public class TNTPoint{ List history, List destroyedBlocks) { this.tntId = tntId; this.explosion = explosion; - this.inWater = tnt.isInWater(); + if (Core.getVersion() > 15) { + this.inWater = tnt.isInWater(); + } else { + this.inWater = false; + } this.afterFirstExplosion = afterFirstExplosion; this.ticksSinceStart = ticksSinceStart; fuse = tnt.getFuseTicks(); From b086fcaa32be34ce92d93bbff6c889830b56befd Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 13 Jul 2025 21:11:18 +0200 Subject: [PATCH 141/153] Refactor validator method in download command --- .../commands/schematiccommand/parts/ViewPart.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ViewPart.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ViewPart.java index 60146d4eb..c1c277f5e 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ViewPart.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ViewPart.java @@ -92,7 +92,7 @@ public class ViewPart extends SWCommand { } @Register("download") - public void download(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node) { + public void download(Player player, @Validator("isSchemValidator") SchematicNode node) { SchematicCommandUtils.download(player, node); } } From cf1422f532adbc8623e438348dd0d3f8c1bc2fbc Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 14 Jul 2025 09:46:06 +0200 Subject: [PATCH 142/153] Fix NodeData query to correctly order by CreatedAt descending --- CommonCore/SQL/src/de/steamwar/sql/NodeData.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/NodeData.java b/CommonCore/SQL/src/de/steamwar/sql/NodeData.java index cc6f0cc93..bd543be0f 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/NodeData.java +++ b/CommonCore/SQL/src/de/steamwar/sql/NodeData.java @@ -51,7 +51,7 @@ public class NodeData { private static final SelectStatement get = new SelectStatement<>(table, "SELECT NodeId, CreatedAt, NodeFormat FROM NodeData WHERE NodeId = ? ORDER BY CreatedAt "); private static final Statement getRevisions = new Statement("SELECT COUNT(DISTINCT CreatedAt) as CNT FROM NodeData WHERE NodeId = ?"); - private static final SelectStatement getLatest = new SelectStatement<>(table, "SELECT NodeId, CreatedAt, NodeFormat FROM NodeData WHERE NodeId = ? ORDER BY CreatedAt LIMIT 1"); + private static final SelectStatement getLatest = new SelectStatement<>(table, "SELECT NodeId, CreatedAt, NodeFormat FROM NodeData WHERE NodeId = ? ORDER BY CreatedAt DESC LIMIT 1"); public static NodeData getLatest(SchematicNode node) { if (node.isDir()) throw new IllegalArgumentException("Node is dir"); From 5a778547525e6c934afa277d362f9c10729b6f26 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 14 Jul 2025 11:20:26 +0200 Subject: [PATCH 143/153] Fix replaceColor usage and correct config flag handling --- CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java | 2 +- .../commands/schematiccommand/SchematicCommandUtils.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java b/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java index 1bfa1f9e3..e355419bb 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java +++ b/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java @@ -467,7 +467,7 @@ public class SchematicNode { } public boolean getConfig(ConfigFlags flag) { - return (config & (1 << flag.ordinal())) == 1; + return (config & (1 << flag.ordinal())) != 0; } public void setConfig(ConfigFlags flag, boolean value) { diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java index b7b610841..ad1ced2e3 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java @@ -492,7 +492,7 @@ public class SchematicCommandUtils { node.setAllowReplay(!node.allowReplay()); submitSchemGUI(player, node, type); }); - inv.setItem(1, SWItem.getMaterial(node.replaceColor() ? "PINK_WOOL" : "LIGHT_GRAY_WOOL"), SchematicSystem.MESSAGE.parse(node.allowReplay()?"UTIL_SUBMIT_COLOR_ON":"UTIL_SUBMIT_COLOR_OFF", player), click -> { + inv.setItem(1, SWItem.getMaterial(node.replaceColor() ? "PINK_WOOL" : "LIGHT_GRAY_WOOL"), SchematicSystem.MESSAGE.parse(node.replaceColor()?"UTIL_SUBMIT_COLOR_ON":"UTIL_SUBMIT_COLOR_OFF", player), click -> { node.setReplaceColor(!node.replaceColor()); submitSchemGUI(player, node, type); }); From 7aba8da5a0b0c7e93100221362c92e17abb795ba Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 14 Jul 2025 13:40:43 +0200 Subject: [PATCH 144/153] Add revision handling to setSchematic method in FightTeam --- .../src/de/steamwar/fightsystem/fight/FightTeam.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 331e3730a..47f73649c 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -416,7 +416,7 @@ public class FightTeam { } public void setSchem(SchematicNode schematic, int revision){ - this.schematic.setSchematic(schematic); + this.schematic.setSchematic(schematic, revision); broadcast("SCHEMATIC_CHOSEN", Config.GameName, schematic.getName()); } From 948cf5e8dbab897db070e42308a5a32d9c0ce26b Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 14 Jul 2025 18:52:08 +0200 Subject: [PATCH 145/153] Add Criu Debug --- .../SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java | 1 + 1 file changed, 1 insertion(+) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java index 2a1894e26..70df82a05 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java @@ -120,6 +120,7 @@ class CheckpointUtilsJ9 { criu.checkpointJVM(); } catch (JVMCRIUException e) { Path logfile = path.resolve("criu.log"); + System.out.println(logfile.toAbsolutePath().toString()); if(logfile.toFile().exists()) throw new IllegalStateException("Could not create checkpoint, criu log:\n" + new String(Files.readAllBytes(logfile)), e); From 00de8525759b6f06ebce71a6597341de2ebbe517 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 14 Jul 2025 19:07:48 +0200 Subject: [PATCH 146/153] Add Criu Debug --- .../src/de/steamwar/core/CheckpointUtilsJ9.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java index 70df82a05..84f354f48 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java @@ -49,7 +49,7 @@ class CheckpointUtilsJ9 { static void freeze() { String checkpointFile = System.getProperty("checkpoint"); - if(!CRIUSupport.isCheckpointAllowed() || checkpointFile == null) { + if(!CRIUSupport.isCheckpointAllowed() || checkpointFile == null || true) { Bukkit.shutdown(); return; } @@ -120,9 +120,10 @@ class CheckpointUtilsJ9 { criu.checkpointJVM(); } catch (JVMCRIUException e) { Path logfile = path.resolve("criu.log"); - System.out.println(logfile.toAbsolutePath().toString()); - if(logfile.toFile().exists()) + if(logfile.toFile().exists()) { + System.out.println("Reading criu log"); throw new IllegalStateException("Could not create checkpoint, criu log:\n" + new String(Files.readAllBytes(logfile)), e); + } throw e; } From 58ab619144bb51c6d46cd0e9ecef14534e5ac485 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 14 Jul 2025 19:08:35 +0200 Subject: [PATCH 147/153] Add Criu Debug --- .../SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java index 84f354f48..c0f85e047 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java @@ -49,7 +49,7 @@ class CheckpointUtilsJ9 { static void freeze() { String checkpointFile = System.getProperty("checkpoint"); - if(!CRIUSupport.isCheckpointAllowed() || checkpointFile == null || true) { + if(!CRIUSupport.isCheckpointAllowed() || checkpointFile == null) { Bukkit.shutdown(); return; } From c682333771d61e00474ce25e368a132eb2dbc380 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 14 Jul 2025 19:13:25 +0200 Subject: [PATCH 148/153] Add Criu Debug --- .../SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java index c0f85e047..685a53e32 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java @@ -134,6 +134,8 @@ class CheckpointUtilsJ9 { port = stream.readInt(); } + System.out.println(port); + // Reopen socket bind.invoke(serverConnection, InetAddress.getLoopbackAddress(), port); if(Core.getVersion() > 12) { From 0464442b83e7357554134d348c907f95b9f21868 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 14 Jul 2025 19:38:46 +0200 Subject: [PATCH 149/153] VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java aktualisiert --- .../Persistent/src/de/steamwar/persistent/Subserver.java | 1 + 1 file changed, 1 insertion(+) diff --git a/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java b/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java index 832bb9f5b..07558176c 100644 --- a/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java +++ b/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java @@ -220,6 +220,7 @@ public class Subserver { try { if (checkpoint) { start(process.getErrorStream(), line -> line.contains("Checkpoint restored")); + Thread.sleep(300); } else { start(process.getInputStream(), line -> { if (line.contains("Loading libraries, please wait")) From 62e674ed429253c12a6af12755f6e9a535372067 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 14 Jul 2025 19:40:33 +0200 Subject: [PATCH 150/153] SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java aktualisiert --- .../SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java index 685a53e32..bee8b27f5 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java @@ -49,7 +49,7 @@ class CheckpointUtilsJ9 { static void freeze() { String checkpointFile = System.getProperty("checkpoint"); - if(!CRIUSupport.isCheckpointAllowed() || checkpointFile == null) { + if(!CRIUSupport.isCheckpointAllowed() || checkpointFile == null || true) { Bukkit.shutdown(); return; } From e06742d6d24a06665926f60f57a7514f5968c261 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 16 Jul 2025 09:34:38 +0200 Subject: [PATCH 151/153] SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java aktualisiert --- .../SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java index bee8b27f5..685a53e32 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java @@ -49,7 +49,7 @@ class CheckpointUtilsJ9 { static void freeze() { String checkpointFile = System.getProperty("checkpoint"); - if(!CRIUSupport.isCheckpointAllowed() || checkpointFile == null || true) { + if(!CRIUSupport.isCheckpointAllowed() || checkpointFile == null) { Bukkit.shutdown(); return; } From 44c06314c692b5a32c7d41f7ceb511cef8f2c1b6 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 16 Jul 2025 09:39:38 +0200 Subject: [PATCH 152/153] Update checkpoint restoration message handling in Subserver --- .../Persistent/src/de/steamwar/persistent/Subserver.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java b/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java index 07558176c..d42908146 100644 --- a/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java +++ b/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java @@ -219,8 +219,7 @@ public class Subserver { Exception ex = null; try { if (checkpoint) { - start(process.getErrorStream(), line -> line.contains("Checkpoint restored")); - Thread.sleep(300); + start(process.getErrorStream(), line -> line.contains("Restore finished successfully.")); } else { start(process.getInputStream(), line -> { if (line.contains("Loading libraries, please wait")) From 3e5055c2469db30ba85a1135a8029ac5851a6b97 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 16 Jul 2025 09:43:24 +0200 Subject: [PATCH 153/153] Refine checkpoint handling in Subserver and remove unnecessary debug logs in CheckpointUtilsJ9 --- .../src/de/steamwar/core/CheckpointUtilsJ9.java | 3 --- .../Persistent/src/de/steamwar/persistent/Subserver.java | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java index 685a53e32..d59197831 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java @@ -121,7 +121,6 @@ class CheckpointUtilsJ9 { } catch (JVMCRIUException e) { Path logfile = path.resolve("criu.log"); if(logfile.toFile().exists()) { - System.out.println("Reading criu log"); throw new IllegalStateException("Could not create checkpoint, criu log:\n" + new String(Files.readAllBytes(logfile)), e); } @@ -134,8 +133,6 @@ class CheckpointUtilsJ9 { port = stream.readInt(); } - System.out.println(port); - // Reopen socket bind.invoke(serverConnection, InetAddress.getLoopbackAddress(), port); if(Core.getVersion() > 12) { diff --git a/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java b/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java index d42908146..22d15f25f 100644 --- a/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java +++ b/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java @@ -220,6 +220,7 @@ public class Subserver { try { if (checkpoint) { start(process.getErrorStream(), line -> line.contains("Restore finished successfully.")); + Thread.sleep(300); } else { start(process.getInputStream(), line -> { if (line.contains("Loading libraries, please wait"))