diff --git a/SpigotCore_10/src/de/steamwar/core/SpigotTPS_10.java b/SpigotCore_10/src/de/steamwar/core/SpigotTPS_10.java new file mode 100644 index 0000000..2cc2d26 --- /dev/null +++ b/SpigotCore_10/src/de/steamwar/core/SpigotTPS_10.java @@ -0,0 +1,32 @@ +/* + 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 net.minecraft.server.v1_10_R1.MinecraftServer; + +public class SpigotTPS_10 { + + private SpigotTPS_10(){} + + static double[] getTps(){ + return MinecraftServer.getServer().recentTps; + } + +} diff --git a/SpigotCore_12/src/de/steamwar/core/SpigotTPS_12.java b/SpigotCore_12/src/de/steamwar/core/SpigotTPS_12.java new file mode 100644 index 0000000..17541c7 --- /dev/null +++ b/SpigotCore_12/src/de/steamwar/core/SpigotTPS_12.java @@ -0,0 +1,32 @@ +/* + 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 net.minecraft.server.v1_12_R1.MinecraftServer; + +public class SpigotTPS_12 { + + private SpigotTPS_12(){} + + static double[] getTps(){ + return MinecraftServer.getServer().recentTps; + } + +} diff --git a/SpigotCore_14/src/de/steamwar/core/SpigotTPS_14.java b/SpigotCore_14/src/de/steamwar/core/SpigotTPS_14.java new file mode 100644 index 0000000..d00aba8 --- /dev/null +++ b/SpigotCore_14/src/de/steamwar/core/SpigotTPS_14.java @@ -0,0 +1,32 @@ +/* + 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 net.minecraft.server.v1_14_R1.MinecraftServer; + +public class SpigotTPS_14 { + + private SpigotTPS_14(){} + + static double[] getTps(){ + return MinecraftServer.getServer().recentTps; + } + +} diff --git a/SpigotCore_15/src/de/steamwar/core/SpigotTPS_15.java b/SpigotCore_15/src/de/steamwar/core/SpigotTPS_15.java new file mode 100644 index 0000000..46c1186 --- /dev/null +++ b/SpigotCore_15/src/de/steamwar/core/SpigotTPS_15.java @@ -0,0 +1,32 @@ +/* + 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 net.minecraft.server.v1_15_R1.MinecraftServer; + +public class SpigotTPS_15 { + + private SpigotTPS_15(){} + + static double[] getTps(){ + return MinecraftServer.getServer().recentTps; + } + +} diff --git a/SpigotCore_8/src/de/steamwar/comms/BungeeReceiver_8.java b/SpigotCore_8/src/de/steamwar/comms/BungeeReceiver_8.java new file mode 100644 index 0000000..2b2ce08 --- /dev/null +++ b/SpigotCore_8/src/de/steamwar/comms/BungeeReceiver_8.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.comms; + +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +public class BungeeReceiver_8 { + + public static void playPling(Player player) { + player.playSound(player.getLocation(), Sound.ORB_PICKUP, 1, 1); + } +} diff --git a/SpigotCore_8/src/de/steamwar/core/SpigotTPS_8.java b/SpigotCore_8/src/de/steamwar/core/SpigotTPS_8.java new file mode 100644 index 0000000..aeb94d1 --- /dev/null +++ b/SpigotCore_8/src/de/steamwar/core/SpigotTPS_8.java @@ -0,0 +1,32 @@ +/* + 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 net.minecraft.server.v1_8_R3.MinecraftServer; + +public class SpigotTPS_8 { + + private SpigotTPS_8(){} + + static double[] getTps(){ + return MinecraftServer.getServer().recentTps; + } + +} diff --git a/SpigotCore_9/src/de/steamwar/comms/BungeeReceiver_9.java b/SpigotCore_9/src/de/steamwar/comms/BungeeReceiver_9.java new file mode 100644 index 0000000..685b65a --- /dev/null +++ b/SpigotCore_9/src/de/steamwar/comms/BungeeReceiver_9.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.comms; + +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +public class BungeeReceiver_9 { + + public static void playpling(Player player) { + player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1); + } +} diff --git a/SpigotCore_9/src/de/steamwar/core/SpigotTPS_9.java b/SpigotCore_9/src/de/steamwar/core/SpigotTPS_9.java new file mode 100644 index 0000000..6a0ba28 --- /dev/null +++ b/SpigotCore_9/src/de/steamwar/core/SpigotTPS_9.java @@ -0,0 +1,32 @@ +/* + 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 net.minecraft.server.v1_9_R2.MinecraftServer; + +public class SpigotTPS_9 { + + private SpigotTPS_9(){} + + static double[] getTps(){ + return MinecraftServer.getServer().recentTps; + } + +} diff --git a/SpigotCore_Main/src/de/steamwar/comms/BungeeReceiver.java b/SpigotCore_Main/src/de/steamwar/comms/BungeeReceiver.java index 0678dc9..70bc593 100644 --- a/SpigotCore_Main/src/de/steamwar/comms/BungeeReceiver.java +++ b/SpigotCore_Main/src/de/steamwar/comms/BungeeReceiver.java @@ -26,6 +26,8 @@ import de.steamwar.comms.handlers.InventoryHandler; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import de.steamwar.sql.*; +import de.steamwar.core.Core; +import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.Sound; @@ -49,7 +51,11 @@ public class BungeeReceiver implements PluginMessageListener { UUID uuid = SteamwarUser.get(byteArrayDataInput.readInt()).getUUID(); if(Bukkit.getPlayer(uuid).isOnline()) { Player player = Bukkit.getPlayer(uuid); - player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.MASTER, 1, 1); + if (Core.getVersion() == 8) { + BungeeReceiver_8.playPling(player); + } else { + BungeeReceiver_9.playpling(player); + } } }); diff --git a/SpigotCore_Main/src/de/steamwar/comms/PacketIdManager.java b/SpigotCore_Main/src/de/steamwar/comms/PacketIdManager.java index 6026b17..5958ae0 100644 --- a/SpigotCore_Main/src/de/steamwar/comms/PacketIdManager.java +++ b/SpigotCore_Main/src/de/steamwar/comms/PacketIdManager.java @@ -23,6 +23,7 @@ public class PacketIdManager { //0x0(X) Standalone Packets public final static byte PING_PACKET = 0x01; + public final static byte TABLIST_NAME = 0x02; //0x1(X) Bungee Inventory public final static byte INVENTORY_PACKET = 0x10; public final static byte INVENTORY_CALLBACK_PACKET = 0x11; diff --git a/SpigotCore_Main/src/de/steamwar/comms/packets/TablistNamePacket.java b/SpigotCore_Main/src/de/steamwar/comms/packets/TablistNamePacket.java new file mode 100644 index 0000000..7f5454e --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/comms/packets/TablistNamePacket.java @@ -0,0 +1,26 @@ +package de.steamwar.comms.packets; + +import com.google.common.io.ByteArrayDataOutput; +import de.steamwar.comms.PacketIdManager; + +public class TablistNamePacket extends SpigotPacket { + + final int swUserId; + final String tablistName; + + public TablistNamePacket(int swUserId, String tablistName){ + this.swUserId = swUserId; + this.tablistName = tablistName; + } + + @Override + public int getName() { + return PacketIdManager.TABLIST_NAME; + } + + @Override + public void writeVars(ByteArrayDataOutput byteArrayDataOutput) { + byteArrayDataOutput.writeInt(swUserId); + byteArrayDataOutput.writeUTF(tablistName); + } +} diff --git a/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore_Main/src/de/steamwar/core/Core.java index 9bc14ef..379795e 100644 --- a/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -65,7 +65,6 @@ public class Core extends JavaPlugin{ ErrorLogger.init(); getServer().getMessenger().registerIncomingPluginChannel(this, "sw:bridge", new BungeeReceiver()); getServer().getMessenger().registerOutgoingPluginChannel(this, "sw:bridge"); - } @Override @@ -76,11 +75,11 @@ public class Core extends JavaPlugin{ public static Core getInstance() { return instance; } + public static int getVersion(){ return version; } - private static void setInstance(Core instance) { Core.instance = instance; } diff --git a/SpigotCore_Main/src/de/steamwar/core/ErrorLogger.java b/SpigotCore_Main/src/de/steamwar/core/ErrorLogger.java index d2061ad..b4ba2f1 100644 --- a/SpigotCore_Main/src/de/steamwar/core/ErrorLogger.java +++ b/SpigotCore_Main/src/de/steamwar/core/ErrorLogger.java @@ -20,14 +20,16 @@ package de.steamwar.core; import de.steamwar.sql.SWException; -import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.Appender; import org.apache.logging.log4j.core.Core; -import org.apache.logging.log4j.core.*; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.appender.AbstractAppender; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.config.plugins.PluginAttribute; import org.apache.logging.log4j.core.config.plugins.PluginFactory; +import org.apache.logging.log4j.spi.StandardLevel; @Plugin(name = "ErrorLogger", category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE) public class ErrorLogger extends AbstractAppender { @@ -53,7 +55,7 @@ public class ErrorLogger extends AbstractAppender { @Override public void append(LogEvent logEvent) { - if(logEvent.getLevel().isLessSpecificThan(Level.WARN)) + if(logEvent.getLevel().intLevel() > StandardLevel.WARN.intLevel()) return; SWException.log(logEvent); diff --git a/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java new file mode 100644 index 0000000..0e37709 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java @@ -0,0 +1,102 @@ +/* + 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.Bukkit; + +public class TPSWatcher { + + private static final double TICK_DEFAULT = 20.0; + + private static final TPSWatcher tps_OneSecond = new TPSWatcher(1000); + private static final TPSWatcher tps_TenSecond = new TPSWatcher(10000); + + private long lastTime = System.currentTimeMillis(); + private double tps = 20.0; + + private TPSWatcher(long timeInterval) { + Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> { + long currentTime = System.currentTimeMillis(); + + if (currentTime > lastTime) + tps = (timeInterval / (double) (currentTime - lastTime)) * TICK_DEFAULT; + + lastTime = currentTime; + }, timeInterval / 50, timeInterval / 50); + } + + public static double getTPS() { + return getTPS(TPSType.ONE_SECOND); + } + + public static double getTPSUnlimited() { + return getTPSUnlimited(TPSType.ONE_SECOND); + } + + public static double getTPS(TPSType tpsType) { + return Math.min(getTPSUnlimited(tpsType), 20.0); + } + + public static double getTPSUnlimited(TPSType tpsType) { + switch (tpsType) { + case TEN_SECONDS: + return round(tps_TenSecond.tps); + case ONE_MINUTE: + return round(getSpigotTPS()[0]); + case FIVE_MINUTES: + return round(getSpigotTPS()[1]); + case TEN_MINUTES: + return round(getSpigotTPS()[2]); + case ONE_SECOND: + default: + return round(tps_OneSecond.tps); + } + } + + private static double[] getSpigotTPS() { + switch (Core.getVersion()) { + case 8: + return SpigotTPS_8.getTps(); + case 9: + return SpigotTPS_9.getTps(); + case 10: + return SpigotTPS_10.getTps(); + case 12: + return SpigotTPS_12.getTps(); + case 14: + return SpigotTPS_14.getTps(); + case 15: + default: + return SpigotTPS_15.getTps(); + } + } + + private static double round(double d) { + return Math.round(d * 10) / 10.0; + } + + public enum TPSType { + ONE_SECOND, + TEN_SECONDS, + ONE_MINUTE, + FIVE_MINUTES, + TEN_MINUTES + } +} diff --git a/SpigotCore_Main/src/de/steamwar/sql/Event.java b/SpigotCore_Main/src/de/steamwar/sql/Event.java index c55260b..3b1e2a4 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/Event.java +++ b/SpigotCore_Main/src/de/steamwar/sql/Event.java @@ -34,6 +34,7 @@ public class Event { private final Timestamp end; private final int maximumTeamMembers; private final boolean publicSchemsOnly; + private final boolean spectateSystem; private Event(ResultSet rs) throws SQLException{ this.eventID = rs.getInt("EventID"); @@ -42,6 +43,7 @@ public class Event { this.end = rs.getTimestamp("End"); this.maximumTeamMembers = rs.getInt("MaximumTeamMembers"); this.publicSchemsOnly = rs.getBoolean("PublicSchemsOnly"); + this.spectateSystem = rs.getBoolean("SpectateSystem"); } public static Event get(int eventID){ @@ -75,4 +77,7 @@ public class Event { public boolean publicSchemsOnly() { return publicSchemsOnly; } + public boolean spectateSystem(){ + return spectateSystem; + } } diff --git a/SpigotCore_Main/src/de/steamwar/sql/SWException.java b/SpigotCore_Main/src/de/steamwar/sql/SWException.java index 31cd1ef..67c2724 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SWException.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SWException.java @@ -23,21 +23,75 @@ import org.apache.logging.log4j.core.LogEvent; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + public class SWException { private SWException(){} private static boolean logDisabled = false; + private static final List ignorereasons; + + static { + List reasons = new ArrayList<>(); + reasons.add("Initializing Legacy Material Support."); + reasons.add("Could not save the list after adding a user."); + reasons.add("Failed to save operators list:"); + reasons.add("Block at"); + reasons.add("POI data mismatch"); + reasons.add("handleDisconnection() called twice"); + reasons.add("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!"); + reasons.add("The server will make no attempt to authenticate usernames. Beware."); + reasons.add("Whilst this makes it possible to use BungeeCord,"); + reasons.add("Please see http://www.spigotmc.org/wiki/firewall-guide/ for further information."); + reasons.add("To change this, set \"online-mode\" to \"true\" in the server.properties file."); + reasons.add("This crash report has been saved to:"); + reasons.add("Could not pass event PlayerQuitEvent to WorldEditSUI"); + reasons.add("[ViaVersion] Failed to remove injection handler"); + reasons.add("[ViaBackwards] Metadata for entity id"); + reasons.add("Something went wrong upgrading!"); + reasons.add("Tried to load unrecognized recipe"); + reasons.add("Invalid BlockState in palette:"); + reasons.add("Could not register alias"); + reasons.add("Can't keep up! Is the server overloaded?"); + reasons.add("\tat "); + reasons.add("java.lang.Exception"); + reasons.add("[ViaVersion] Ignoring"); + reasons.add("[ViaBackwards] Ignoring"); + ignorereasons = Collections.unmodifiableList(reasons); + } public static void log(LogEvent logEvent){ if(logDisabled) return; - String server = Bukkit.getWorlds().get(0).getName(); - StringBuilder stacktrace = new StringBuilder(logEvent.getSource().toString()); + String message = logEvent.getMessage().getFormattedMessage(); + for(String reason : ignorereasons) + if(message.startsWith(reason)) + return; + if(message.contains("moved too quickly!") || message.contains("moved wrongly!") || message.contains("was kicked for floating too long!")) + return; + + switch (message) { + case "The server has stopped responding!": + logDisabled = true; + return; + case "------------------------------": + message = "Server stopped responding"; + logDisabled = true; + break; + case "Exception stopping the server": + logDisabled = true; + break; + default: + } + + StringBuilder stacktrace = new StringBuilder(logEvent.getSource().toString()); Throwable throwable = logEvent.getThrown(); while(throwable != null){ - stacktrace.append("\nCaused by ").append(throwable.getMessage()); + stacktrace.append("\nCaused by ").append(throwable.getClass().getName()).append(": ").append(throwable.getMessage()); for(StackTraceElement ste : throwable.getStackTrace()) stacktrace.append("\n").append(ste.toString()); @@ -46,31 +100,19 @@ public class SWException { } String st = stacktrace.toString(); - - String message = logEvent.getMessage().getFormattedMessage(); - if(message.startsWith("Block at") || message.startsWith("POI data mismatch") || st.contains("POI data mismatch")) - return; - else if(message.equals("The server has stopped responding!")){ - logDisabled = true; - return; - }else if(message.equals("------------------------------")){ - message = "Server stopped responding"; - logDisabled = true; - }else if(message.equals("Exception stopping the server")){ - logDisabled = true; - }else if(message.startsWith("This crash report has been saved to:") || message.startsWith("Could not pass event PlayerQuitEvent to WorldEditSUI")){ - return; - }else if(message.startsWith("[ViaVersion] Failed to remove injection handler") || message.startsWith("Something went wrong upgrading!")) - return; - else if(message.startsWith("Tried to load unrecognized recipe")) + if(st.contains("POI data mismatch")) return; - - message += "\n\n"; - + message += "\n"; for(Player player : Bukkit.getOnlinePlayers()) message += player.getName() + " "; + String server; + if(Bukkit.getWorlds().isEmpty()) + server = Bukkit.getName(); + else + server = Bukkit.getWorlds().get(0).getName(); + SQL.update("INSERT INTO Exception (server, message, stacktrace) VALUES (?, ?, ?)", server, message, st); }