From 78c0bc51b9fc6a79e9363bda054afc17fb06f7da Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 30 Jan 2024 16:06:53 +0100 Subject: [PATCH 1/7] Fix SimulatorSaver --- .../data/redstone/RedstonePhase.java | 2 +- .../features/tpslimit/TPSSystem.java | 66 ++++++++++--------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstonePhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstonePhase.java index f2b99d36..614be659 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstonePhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstonePhase.java @@ -54,7 +54,7 @@ public final class RedstonePhase extends SimulatorPhase { block.setType(Material.REDSTONE_BLOCK); } }); - tickEnd.accept(tickOffset + lifetime, new SimulatorAction(0, 1) { + tickStart.accept(tickOffset + lifetime, new SimulatorAction(ORDER_LIMIT + 1, 1) { @Override public void accept(World world) { BlockState state = blockState.get(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java index 43eb40da..4368966f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java @@ -26,33 +26,31 @@ import de.steamwar.bausystem.linkage.specific.BauGuiItem; import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.utils.ScoreboardElement; +import de.steamwar.bausystem.utils.TickEndEvent; 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.command.TypeValidator; 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.api.Plain; import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.boss.BarColor; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; -import org.bukkit.scheduler.BukkitRunnable; -import org.bukkit.scheduler.BukkitTask; import java.util.Arrays; -import java.util.concurrent.atomic.AtomicInteger; @Linked -public class TPSSystem implements Plain { +public class TPSSystem implements Listener { @Getter private double currentTPSLimit = 20; @@ -87,12 +85,9 @@ public class TPSSystem implements Plain { instance = this; } - private BukkitTask stepper = null; - private void setTPS(double tps) { - if (stepper != null) { - stepper.cancel(); - stepper = null; + if (currentlyStepping) { + currentlyStepping = false; Bukkit.getOnlinePlayers().forEach(player -> { BossBarService.instance.remove(player, GlobalRegion.getInstance(), "TickStep"); }); @@ -120,27 +115,34 @@ public class TPSSystem implements Plain { }); } - private void setSkip(int steps, double tpsLimitToUse) { - double currentLimit = tpsLimitToUse == 20 ? 0 : currentTPSLimit; - setTPS(tpsLimitToUse); - stepper = new BukkitRunnable() { - AtomicInteger stepsLeft = new AtomicInteger(steps); + private boolean currentlyStepping = false; + private double currentLimit; + private int stepsTotal; + private int stepsLeft; - @Override - public void run() { - if (steps > 1) { - 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, (steps - stepsLeft.get()), steps)); - bossbar.setProgress((steps - stepsLeft.get()) / (double) steps); - }); - } - if (stepsLeft.decrementAndGet() < 0) { - setTPS(currentLimit); - } - } - }.runTaskTimer(BauSystem.getInstance(), 1, 1); + private void setSkip(int steps, double tpsLimitToUse) { + currentLimit = tpsLimitToUse == 20 ? 0 : currentTPSLimit; + setTPS(tpsLimitToUse); + stepsLeft = steps; + stepsTotal = steps; + currentlyStepping = true; + } + + @EventHandler + public void onTickEnd(TickEndEvent event) { + if (!currentlyStepping) return; + if (stepsTotal > 1) { + 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); + }); + } + stepsLeft--; + if (stepsLeft <= 0) { + setTPS(currentLimit); + } } public TypeValidator player() { @@ -341,7 +343,7 @@ public class TPSSystem implements Plain { @Override public String get(Region region, Player p) { - if (TPSSystem.getInstance().stepper != null) { + if (TPSSystem.getInstance().currentlyStepping) { long time = System.currentTimeMillis() % 1000; if (time < 250) { return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: §7•••"; From b891c5adf111a4ace5072c52310ce138e620957d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 30 Jan 2024 19:48:43 +0100 Subject: [PATCH 2/7] Fix TPSSystem --- .../src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java | 1 + 1 file changed, 1 insertion(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java index 4368966f..388e0dbf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java @@ -31,6 +31,7 @@ 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.command.TypeValidator; import de.steamwar.core.Core; import de.steamwar.core.TPSWarpUtils; import de.steamwar.core.TPSWatcher; From f83ba6ab964ae71c3297e97c60422bc2235c328e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 1 Feb 2024 20:02:43 +0100 Subject: [PATCH 3/7] Fix AxiomPermissionCheck --- .../bausystem/features/world/AxiomPermissionCheck.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java index 5ee07dae..05faf23a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java @@ -32,7 +32,10 @@ public class AxiomPermissionCheck implements Listener { @EventHandler public void onAxiomHandshake(AxiomHandshakeEvent event) { - if (Permission.WORLDEDIT.hasPermission(event.getPlayer())) return; + if (Permission.WORLDEDIT.hasPermission(event.getPlayer())) { + event.setMaxBufferSize(Short.MAX_VALUE); + return; + } event.setCancelled(true); } } From 2ba51e66e01024f069ce6079f07bb7e1dad8474b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 1 Feb 2024 21:48:14 +0100 Subject: [PATCH 4/7] Fix BindCommand --- .../bausystem/features/util/BindCommand.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/BindCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/BindCommand.java index ab213c83..c0190486 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/BindCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/BindCommand.java @@ -1,9 +1,17 @@ package de.steamwar.bausystem.features.util; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.event.platform.CommandEvent; +import com.sk89q.worldedit.extension.platform.Actor; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.features.script.ScriptCommand; import de.steamwar.bausystem.features.script.ScriptRunner; +import de.steamwar.bausystem.features.world.WorldEditListener; +import de.steamwar.bausystem.utils.WorldEditUtils; import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; @@ -20,14 +28,18 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataType; +import org.luaj.vm2.LuaValue; import java.lang.reflect.Field; import java.util.*; +import java.util.logging.Level; import java.util.stream.Collectors; @Linked public class BindCommand extends SWCommand implements Listener { + private static final boolean hasFAWE = Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null; + @Linked public static class UnBindCommand extends SWCommand { @@ -107,7 +119,21 @@ public class BindCommand extends SWCommand implements Listener { PlayerCommandPreprocessEvent playerCommandPreprocessEvent = new PlayerCommandPreprocessEvent(event.getPlayer(), "/" + command); Bukkit.getPluginManager().callEvent(playerCommandPreprocessEvent); if (playerCommandPreprocessEvent.isCancelled()) return; - Bukkit.getServer().dispatchCommand(event.getPlayer(), command); + + Bukkit.getLogger().log(Level.INFO, event.getPlayer().getName() + " dispatched command: " + command); + String[] commandSplit = command.split(" "); + if (!commandSplit[0].equals("select") && hasFAWE && WorldEditListener.isWorldEditCommand("/" + commandSplit[0])) { + if (!Permission.WORLDEDIT.hasPermission(event.getPlayer())) { + return; + } + EditSession editSession = WorldEditUtils.getEditSession(event.getPlayer()); + Actor actor = BukkitAdapter.adapt(event.getPlayer()); + WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().handleCommandOnCurrentThread(new CommandEvent(actor, command, editSession)); + editSession.flushSession(); + WorldEditUtils.addToPlayer(event.getPlayer(), editSession); + } else { + Bukkit.getServer().dispatchCommand(event.getPlayer(), command); + } }, 1); } From b211f9cf79ceb4176968102ad9541e3939013ebf Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 4 Feb 2024 01:18:50 +0100 Subject: [PATCH 5/7] Hot Hot Hot-fix Players on Bauserver without add --- .../features/world/AntiBauAddMemberFix.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiBauAddMemberFix.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiBauAddMemberFix.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiBauAddMemberFix.java new file mode 100644 index 00000000..c406f5c7 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiBauAddMemberFix.java @@ -0,0 +1,44 @@ +/* + * 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.bausystem.features.world; + +import de.steamwar.bausystem.config.BauServer; +import de.steamwar.linkage.Linked; +import de.steamwar.sql.BauweltMember; +import de.steamwar.sql.SteamwarUser; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +@Linked +public class AntiBauAddMemberFix implements Listener { + + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + if (event.getPlayer().getUniqueId().equals(BauServer.getInstance().getOwner())) { + return; + } + if (BauweltMember.getBauMember(BauServer.getInstance().getOwner(), event.getPlayer().getUniqueId()) == null) { + event.getPlayer().kickPlayer(""); + throw new SecurityException("The player " + event.getPlayer().getName() + " joined on the server of " + SteamwarUser.get(BauServer.getInstance().getOwnerID()).getUserName() + " without being added!"); + } + } +} From 7ded9eefa404aec6e9a48b3452b0072b7aee4537 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 6 Feb 2024 22:39:33 +0100 Subject: [PATCH 6/7] Potential WE axe fix --- .../steamwar/bausystem/features/world/AFKStopperListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java index 263324c3..81e2f4dd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java @@ -63,7 +63,7 @@ public class AFKStopperListener implements Listener { afkTicks = 0; } - @EventHandler + @EventHandler(priority = EventPriority.LOWEST) //Potential fix for potential race condition with WE axe spontaneously not working public void onPlayerJoin(PlayerJoinEvent event) { event.getPlayer().setOp(true); } From c2c686319db38f0af5f91cfc419c7d756241831c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 11 Feb 2024 15:17:07 +0100 Subject: [PATCH 7/7] Fix ServerLib --- .../bausystem/features/script/lua/libs/ServerLib.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java index 80134fba..2a28bf16 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java @@ -20,6 +20,8 @@ package de.steamwar.bausystem.features.script.lua.libs; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; +import de.steamwar.bausystem.features.tpslimit.TPSSystem; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.core.TPSWatcher; import de.steamwar.inventory.SWItem; @@ -75,7 +77,7 @@ public class ServerLib 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(TPSLimitUtils::getCurrentTPSLimit)); + tpsLib.set("limit", getter(TPSSystem.getInstance()::getCurrentTPSLimit)); serverLib.set("tps", tpsLib); return serverLib;