Reformatting, update to 1.17, performance and general improvements, improved WaterWalk

This commit is contained in:
Rammelkast committed 2021-06-30 19:32:37 +02:00
1 parent f637facbea
commit 7739eb9ca0
19 files changed
+676 -705

No files matched your search

@@ -16,14 +16,14 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@@ -48,18 +48,18 @@ import com.rammelkast.anticheatreloaded.util.UpdateManager;
import com.rammelkast.anticheatreloaded.util.User;
import com.rammelkast.anticheatreloaded.util.VersionUtil;
public class AntiCheatReloaded extends JavaPlugin {
public final class AntiCheatReloaded extends JavaPlugin {
public static final String PREFIX = ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.DARK_GRAY + "> ";
public static final List<UUID> MUTE_ENABLED_MODS = new ArrayList<UUID>();
private static AntiCheatManager manager;
private static AntiCheatReloaded plugin;
private static AntiCheatManager manager;
private static ExecutorService executorService;
private static List<Listener> eventList = new ArrayList<Listener>();
private static Configuration config;
private static boolean verbose;
private static ProtocolManager protocolManager;
private static SecureRandom random;
private static Long loadTime;
private static UpdateManager updateManager;
private double tps = -1;
@@ -68,9 +68,12 @@ public class AntiCheatReloaded extends JavaPlugin {
@Override
public void onEnable() {
plugin = this;
random = new SecureRandom();
loadTime = System.currentTimeMillis();
manager = new AntiCheatManager(this, getLogger());
final int threads = Math.max(1, Runtime.getRuntime().availableProcessors() / 4);
executorService = Executors.newFixedThreadPool(threads);
Bukkit.getConsoleSender().sendMessage(PREFIX + ChatColor.GRAY + "Pool size is " + threads + " threads");
eventList.add(new PlayerListener());
eventList.add(new BlockListener());
eventList.add(new EntityListener());
@@ -78,32 +81,29 @@ public class AntiCheatReloaded extends JavaPlugin {
eventList.add(new InventoryListener());
// Order is important in some cases, don't screw with these unless
// needed, especially config
this.setupConfig();
this.setupEvents();
this.setupCommands();
setupConfig();
setupEvents();
setupCommands();
// Enterprise must come before levels
this.setupEnterprise();
this.restoreLevels();
setupEnterprise();
restoreLevels();
if (Bukkit.getPluginManager().getPlugin("ProtocolLib") != null) {
this.setupProtocol();
setupProtocol();
} else {
Bukkit.getConsoleSender().sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.DARK_GRAY + "> " + ChatColor.RED
Bukkit.getConsoleSender().sendMessage(PREFIX + ChatColor.RED
+ "Could not find ProtocolLib. Shutting down!");
Bukkit.getPluginManager().disablePlugin(this);
return;
}
Bukkit.getConsoleSender()
.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.DARK_GRAY + "> " + ChatColor.GRAY
+ "Running Minecraft version " + VersionUtil.getVersion() + " "
.sendMessage(PREFIX + ChatColor.GRAY + "Running Minecraft version " + VersionUtil.getVersion() + " "
+ (VersionUtil.isSupported() ? (ChatColor.GREEN + "(supported)")
: (ChatColor.RED + "(NOT SUPPORTED!)")));
getLogger().info("Enabling packet listeners");
PacketListener.listenMovementPackets();
PacketListener.listenKeepAlivePackets();
PacketListener.listenUseItemPackets();
getLogger().info("Loading packet listener");
PacketListener.load(protocolManager);
updateManager = new UpdateManager();
@@ -120,7 +120,7 @@ public class AntiCheatReloaded extends JavaPlugin {
metrics.addCustomChart(new Metrics.SingleLineChart("cheaters_kicked", new Callable<Integer>() {
@Override
public Integer call() throws Exception {
int kicked = playersKicked;
final int kicked = playersKicked;
// Reset so we don't keep sending the same value
playersKicked = 0;
return kicked;
@@ -152,34 +152,38 @@ public class AntiCheatReloaded extends JavaPlugin {
// Launch TPS check
new BukkitRunnable() {
long sec;
long currentSec;
long second;
long currentSecond;
int ticks;
public void run() {
sec = (System.currentTimeMillis() / 1000L);
if (currentSec == sec) {
second = (System.currentTimeMillis() / 1000L);
if (currentSecond == second) {
ticks += 1;
} else {
currentSec = sec;
currentSecond = second;
tps = (tps == 0.0D ? ticks : (tps + ticks) / 2.0D);
ticks = 1;
}
// Check for updates every 12 hours
if (ticks % 864000 == 0)
if (ticks % 864000 == 0) {
updateManager.update();
}
}
}.runTaskTimer(this, 40L, 1L);
}
@Override
public void onDisable() {
// Cancel all running tasks
getServer().getScheduler().cancelTasks(this);
// Save user levels
verboseLog("Saving user levels...");
config.getLevels().saveLevelsFromUsers(getManager().getUserManager().getUsers());
config.getLevels().saveLevelsFromUsers(manager.getUserManager().getUsers());
AntiCheatManager.close();
getServer().getScheduler().cancelTasks(this);
cleanup();
}
@@ -233,19 +237,18 @@ public class AntiCheatReloaded extends JavaPlugin {
public static AntiCheatManager getManager() {
return manager;
}
public static SecureRandom getRandom() {
return random;
}
public static String getVersion() {
return manager.getPlugin().getDescription().getVersion();
}
private void cleanup() {
eventList = null;
manager = null;
plugin = null;
eventList = null;
config = null;
protocolManager = null;
updateManager = null;
}
public static void debugLog(final String string) {
@@ -268,10 +271,6 @@ public class AntiCheatReloaded extends JavaPlugin {
verbose = b;
}
public Long getLoadTime() {
return loadTime;
}
public static ProtocolManager getProtocolManager() {
return protocolManager;
}
@@ -326,13 +325,20 @@ public class AntiCheatReloaded extends JavaPlugin {
this.symbiosisMetric += ", Negativity";
}
}
if (Bukkit.getPluginManager().getPlugin("SoaromaSAC") != null) {
if (this.symbiosisMetric.equals("None")) {
this.symbiosisMetric = "SoaromaSAC";
} else {
this.symbiosisMetric += ", SoaromaSAC";
}
}
}
public static void sendToMainThread(Runnable runnable) {
Bukkit.getScheduler().runTask(AntiCheatReloaded.getPlugin(), runnable);
}
public void sendToStaff(String message) {
public void sendToStaff(final String message) {
Bukkit.getOnlinePlayers().forEach(player -> {
if (player.hasPermission("anticheat.system.alert")) {
if (!MUTE_ENABLED_MODS.contains(player.getUniqueId())) {
@@ -346,11 +352,12 @@ public class AntiCheatReloaded extends JavaPlugin {
return updateManager;
}
public static ExecutorService getExecutor() {
return executorService;
}
public double getTPS() {
if (this.tps < 0 || this.tps > 20) {
return 20;
}
return this.tps;
return Math.min(Math.max(this.tps, 0.0D), 20.0D);
}
}