Add nspt command

Also add configurable flight checks, and removed a unused method in BlockPosition
This commit is contained in:
Ivan Pekov 2020-09-30 18:35:35 +03:00
parent 239a43721f
commit db58abea26
No known key found for this signature in database
GPG Key ID: BC975C392D9CA3A3
4 changed files with 196 additions and 16 deletions

View File

@ -20,6 +20,7 @@ # Patches
| api | Add last tick time API | Ivan Pekov | tr7zw |
| server | Add last tick time API | Ivan Pekov | tr7zw |
| server | Add no-tick block list | William Blake Galbreath | |
| server | Add nspt command | Ivan Pekov | |
| server | Add option to disable dolphin treasure searching | William Blake Galbreath | |
| server | Add option to disable observer clocks | Phoenix616 | |
| server | Add option to disable saving projectiles to disk | William Blake Galbreath | |
@ -40,6 +41,7 @@ # Patches
| server | Breedable Polar Bears | William Blake Galbreath | |
| server | Charged creeper naturally spawn | William Blake Galbreath | |
| server | Configurable TPS Catchup | William Blake Galbreath | |
| server | Configurable flight checks | Ivan Pekov | |
| server | Configurable villager brain ticks | William Blake Galbreath | |
| server | Cows eat mushrooms | William Blake Galbreath | |
| api | Default permissions | William Blake Galbreath | |

View File

@ -25,10 +25,10 @@ index c1f992b2ebac9819085bec74bc40ca3b5384c741..462d3431367f97f9d8506fd1a1adf8dc
return this.getBlock().a(block);
}
diff --git a/src/main/java/net/minecraft/server/BlockPosition.java b/src/main/java/net/minecraft/server/BlockPosition.java
index e6b5a21c523c598f53207d024322301fbae74825..294ef31838b750b45187dcf76b43d06729cce00c 100644
index e6b5a21c523c598f53207d024322301fbae74825..160783a6660048b660e49382cd874ef89b47fb5c 100644
--- a/src/main/java/net/minecraft/server/BlockPosition.java
+++ b/src/main/java/net/minecraft/server/BlockPosition.java
@@ -318,9 +318,29 @@ public class BlockPosition extends BaseBlockPosition {
@@ -318,7 +318,17 @@ public class BlockPosition extends BaseBlockPosition {
}
public static Optional<BlockPosition> a(BlockPosition blockposition, int i, int j, Predicate<BlockPosition> predicate) {
@ -46,20 +46,8 @@ index e6b5a21c523c598f53207d024322301fbae74825..294ef31838b750b45187dcf76b43d067
+ // Yatopia end
}
+ // Yatopia start
+ public static java.util.List<BlockPosition> bList(BlockPosition pos, int i, int j, int k) {
+ java.util.List<BlockPosition> ret = new java.util.ArrayList<>();
+ Iterable<BlockPosition> iterable = a(pos, i, j, k);
+ net.yatopia.server.HoldingConsumer<BlockPosition> consumer = new net.yatopia.server.HoldingConsumer<>();
+ java.util.Spliterator<BlockPosition> spliterator = iterable.spliterator();
+ while (spliterator.tryAdvance(consumer)) ret.add(consumer.getValue());
+ return ret;
+ }
+ // Yatopia end
public static Stream<BlockPosition> b(BlockPosition blockposition, int i, int j, int k) {
return StreamSupport.stream(a(blockposition, i, j, k).spliterator(), false);
}
@@ -329,6 +349,16 @@ public class BlockPosition extends BaseBlockPosition {
@@ -329,6 +339,16 @@ public class BlockPosition extends BaseBlockPosition {
return b(Math.min(blockposition.getX(), blockposition1.getX()), Math.min(blockposition.getY(), blockposition1.getY()), Math.min(blockposition.getZ(), blockposition1.getZ()), Math.max(blockposition.getX(), blockposition1.getX()), Math.max(blockposition.getY(), blockposition1.getY()), Math.max(blockposition.getZ(), blockposition1.getZ()));
}
@ -76,7 +64,7 @@ index e6b5a21c523c598f53207d024322301fbae74825..294ef31838b750b45187dcf76b43d067
public static Stream<BlockPosition> b(BlockPosition blockposition, BlockPosition blockposition1) {
return StreamSupport.stream(a(blockposition, blockposition1).spliterator(), false);
}
@@ -337,6 +367,11 @@ public class BlockPosition extends BaseBlockPosition {
@@ -337,6 +357,11 @@ public class BlockPosition extends BaseBlockPosition {
return a(Math.min(structureboundingbox.a, structureboundingbox.d), Math.min(structureboundingbox.b, structureboundingbox.e), Math.min(structureboundingbox.c, structureboundingbox.f), Math.max(structureboundingbox.a, structureboundingbox.d), Math.max(structureboundingbox.b, structureboundingbox.e), Math.max(structureboundingbox.c, structureboundingbox.f));
}

View File

@ -0,0 +1,145 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ivan Pekov <ivan@mrivanplays.com>
Date: Wed, 30 Sep 2020 18:05:45 +0300
Subject: [PATCH] Add nspt command
diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java
index 6c280d64bb069fba0d52a7d8b4eb6a0816354cc1..15ccdad0f46297c30ed603879db467608c410df4 100644
--- a/src/main/java/net/minecraft/server/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/DedicatedServer.java
@@ -184,6 +184,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
DedicatedServer.LOGGER.error("Unable to load server configuration", e);
return false;
}
+ net.yatopia.server.YatopiaConfig.registerCommands();
de.minebench.origami.OrigamiConfig.init((java.io.File) options.valueOf("origami-settings"));
// Yatopia end
this.setPVP(dedicatedserverproperties.pvp);
diff --git a/src/main/java/net/yatopia/server/NSPTCommand.java b/src/main/java/net/yatopia/server/NSPTCommand.java
new file mode 100644
index 0000000000000000000000000000000000000000..863fbde3162b5aa59e7631e4b401106f7ccc7d90
--- /dev/null
+++ b/src/main/java/net/yatopia/server/NSPTCommand.java
@@ -0,0 +1,59 @@
+package net.yatopia.server;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import net.minecraft.server.MinecraftServer;
+import org.bukkit.ChatColor;
+import org.bukkit.Location;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+
+public class NSPTCommand extends Command {
+
+ public NSPTCommand(String name) {
+ super(name);
+ this.description = "View server tick times in nanoseconds";
+ this.usageMessage = "/nspt";
+ this.setPermission("bukkit.command.nspt");
+ }
+
+ @Override
+ public List<String> tabComplete(CommandSender sender, String alias, String[] args, Location location) throws IllegalArgumentException {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String commandLabel, String[] args) {
+ if (!testPermission(sender)) return true;
+
+ MinecraftServer server = MinecraftServer.getServer();
+
+ List<String> times = new ArrayList<>();
+ times.addAll(eval(server.tickTimes5s.getTimes()));
+ times.addAll(eval(server.tickTimes10s.getTimes()));
+ times.addAll(eval(server.tickTimes60s.getTimes()));
+
+ sender.sendMessage("§6Server tick NS times §e(§7avg§e/§7min§e/§7max§e)§6 from last 5s§7,§6 10s§7,§6 1m§e:");
+ sender.sendMessage(String.format("§6◴ %s§7/%s§7/%s§e, %s§7/%s§7/%s§e, %s§7/%s§7/%s", times.toArray()));
+ return true;
+ }
+
+ private static List<String> eval(long[] times) {
+ long min = Integer.MAX_VALUE;
+ long max = 0L;
+ long total = 0L;
+ for (long value : times) {
+ if (value > 0L && value < min) min = value;
+ if (value > max) max = value;
+ total += value;
+ }
+ double avgD = ((double) total / (double) times.length);
+ return Arrays.asList(getColor(avgD), getColor(min), getColor(max));
+ }
+
+ private static String getColor(double avg) {
+ return ChatColor.COLOR_CHAR + (avg >= 5E+7 ? "c" : avg >= (4E+7) ? "e" : "a") + avg;
+ }
+}
diff --git a/src/main/java/net/yatopia/server/YatopiaConfig.java b/src/main/java/net/yatopia/server/YatopiaConfig.java
index 0237e91512dd15dae1597f1cbb37b0fb178ae35e..e4c5a485caa9e97388aefd9dc5a3ce40efeca738 100644
--- a/src/main/java/net/yatopia/server/YatopiaConfig.java
+++ b/src/main/java/net/yatopia/server/YatopiaConfig.java
@@ -6,12 +6,15 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.regex.Pattern;
import net.minecraft.server.MinecraftServer;
import org.bukkit.Bukkit;
+import org.bukkit.command.Command;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -25,6 +28,7 @@ public class YatopiaConfig {
public static YamlConfiguration config;
public static int version; // since we're remapping sidestreams' configs we need this public
public static boolean verbose; // since we're remapping sidestreams' configs we need this public
+ private static Map<String, Command> commands;
/*========================================================================*/
public static void init(File configFile) {
@@ -40,6 +44,8 @@ public class YatopiaConfig {
config.options().header(HEADER);
config.options().copyDefaults(true);
verbose = getBoolean("verbose", false);
+ commands = new HashMap<>();
+ commands.put("nspt", new NSPTCommand("nspt"));
version = getInt("config-version", 1);
set("config-version", 1);
@@ -47,6 +53,12 @@ public class YatopiaConfig {
readConfig(YatopiaConfig.class, null);
}
+ public static void registerCommands() {
+ for (Map.Entry<String, Command> entry : commands.entrySet()) {
+ MinecraftServer.getServer().server.getCommandMap().register(entry.getKey(), "Yatopia", entry.getValue());
+ }
+ }
+
private static void removeLeftovers() {
// this method is only to remove non-used values in the config
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 78d7fc805a1aeb0d31e51a5aa68e92d9ffd7ba73..e64614c7c98ecc1dfc5aa6de07db07eeb399d351 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -902,6 +902,7 @@ public final class CraftServer implements Server {
org.spigotmc.SpigotConfig.registerCommands(); // Spigot
com.destroystokyo.paper.PaperConfig.registerCommands(); // Paper
net.pl3x.purpur.PurpurConfig.registerCommands(); // Purpur
+ net.yatopia.server.YatopiaConfig.registerCommands(); // Yatopia
overrideAllCommandBlockCommands = commandsConfiguration.getStringList("command-block-overrides").contains("*");
ignoreVanillaPermissions = commandsConfiguration.getBoolean("ignore-vanilla-permissions");

View File

@ -0,0 +1,45 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ivan Pekov <ivan@mrivanplays.com>
Date: Wed, 30 Sep 2020 18:20:12 +0300
Subject: [PATCH] Configurable flight checks
Original code by MrBoom, but he had invalid git credentials.
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
index 4fac720564b8687fae59c0f2e4898a48b16a9105..0d583ad962bc3bd24dc9e3da9fea33d694532176 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -166,7 +166,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
++this.e;
this.processedMovePackets = this.receivedMovePackets;
if (this.B && !this.player.isSleeping()) {
- if (++this.C > 80) {
+ if (net.yatopia.server.YatopiaConfig.checkFlying && ++this.C > 80) { // Yatopia
PlayerConnection.LOGGER.warn("{} was kicked for floating too long!", this.player.getDisplayName().getString());
this.disconnect(com.destroystokyo.paper.PaperConfig.flyingKickPlayerMessage); // Paper - use configurable kick message
return;
@@ -185,7 +185,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
this.w = this.r.locY();
this.x = this.r.locZ();
if (this.D && this.player.getRootVehicle().getRidingPassenger() == this.player) {
- if (++this.E > 80) {
+ if (net.yatopia.server.YatopiaConfig.checkVehicleFlying && ++this.E > 80) { // Yatopia
PlayerConnection.LOGGER.warn("{} was kicked for floating a vehicle too long!", this.player.getDisplayName().getString());
this.disconnect(com.destroystokyo.paper.PaperConfig.flyingKickVehicleMessage); // Paper - use configurable kick message
return;
diff --git a/src/main/java/net/yatopia/server/YatopiaConfig.java b/src/main/java/net/yatopia/server/YatopiaConfig.java
index e4c5a485caa9e97388aefd9dc5a3ce40efeca738..f0e7684304cab9cea05fa266a66a2ad8172c55b6 100644
--- a/src/main/java/net/yatopia/server/YatopiaConfig.java
+++ b/src/main/java/net/yatopia/server/YatopiaConfig.java
@@ -246,4 +246,11 @@ public class YatopiaConfig {
public static boolean isProxy() {
return org.spigotmc.SpigotConfig.bungee || com.destroystokyo.paper.PaperConfig.velocitySupport;
}
+
+ public static boolean checkFlying = true;
+ public static boolean checkVehicleFlying = true;
+ private static void flightChecks() {
+ checkFlying = getBoolean("settings.checks.flight", checkFlying);
+ checkVehicleFlying = getBoolean("settings.checks.vehicle-flight", checkVehicleFlying);
+ }
}