Yatopia/patches/server/0004-Yatopia-configuration.patch
2021-06-16 23:48:55 +02:00

336 lines
14 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: tr7zw <tr7zw@live.de>
Date: Wed, 5 Aug 2020 08:05:10 -0500
Subject: [PATCH] Yatopia configuration
also some basic settings that dont deserve a patch
diff --git a/src/main/java/co/aikar/timings/TimingsExport.java b/src/main/java/co/aikar/timings/TimingsExport.java
index 2ff4d4921e2076abf415bd3c8f5173ecd6222168..5984517724249825c637332647ca83c87cc4d264 100644
--- a/src/main/java/co/aikar/timings/TimingsExport.java
+++ b/src/main/java/co/aikar/timings/TimingsExport.java
@@ -228,7 +228,8 @@ public class TimingsExport extends Thread {
parent.put("config", createObject(
pair("spigot", mapAsJSON(Bukkit.spigot().getSpigotConfig(), null)),
pair("bukkit", mapAsJSON(Bukkit.spigot().getBukkitConfig(), null)),
- pair("paper", mapAsJSON(Bukkit.spigot().getPaperConfig(), null))
+ pair("paper", mapAsJSON(Bukkit.spigot().getPaperConfig(), null)),
+ pair("yatopia", mapAsJSON(Bukkit.spigot().getYatopiaConfig(), null)) // Yatopia - add config to timings report
));
new TimingsExport(listeners, parent, history).start();
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
index eeefbb86cb88bd1b132bb6e22b4a4572cfb5e22c..c01767ca9464fa42844d6b278c1de1555f40ec77 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
@@ -222,6 +222,15 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
io.papermc.paper.brigadier.PaperBrigadierProviderImpl.INSTANCE.getClass(); // init PaperBrigadierProvider
// Paper end
+ // Yatopia start
+ try {
+ org.yatopiamc.yatopia.server.YatopiaConfig.init((java.io.File) options.valueOf("yatopia-settings"));
+ } catch (Exception e) {
+ DedicatedServer.LOGGER.error("Unable to load server configuration", e);
+ return false;
+ }
+ // Yatopia end
+
this.setPvpAllowed(dedicatedserverproperties.pvp);
this.setFlightAllowed(dedicatedserverproperties.allowFlight);
this.setResourcePack(dedicatedserverproperties.resourcePack, this.getPackHash());
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index d6ecf7671663957b27ee0cadbfc57ce3a7be161c..cedc14221393121279427b88b2ddb7ef4ffcbda0 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -265,7 +265,7 @@ public abstract class PlayerList {
// Spigot - view distance
playerconnection.send(new ClientboundLoginPacket(player.getId(), player.gameMode.getGameModeForPlayer(), player.gameMode.getPreviousGameModeForPlayer(), BiomeManager.obfuscateSeed(worldserver1.getSeed()), worlddata.isHardcore(), this.server.levelKeys(), this.registryHolder, worldserver1.dimensionType(), worldserver1.dimension(), this.getMaxPlayers(), worldserver1.getChunkSource().chunkMap.getLoadViewDistance(), flag1, !flag, worldserver1.isDebug(), worldserver1.isFlat())); // Paper - no-tick view distance
player.getBukkitEntity().sendSupportedChannels(); // CraftBukkit
- playerconnection.send(new ClientboundCustomPayloadPacket(ClientboundCustomPayloadPacket.BRAND, (new FriendlyByteBuf(Unpooled.buffer())).writeUtf(this.getServer().getServerModName())));
+ playerconnection.send(new ClientboundCustomPayloadPacket(ClientboundCustomPayloadPacket.BRAND, (new FriendlyByteBuf(Unpooled.buffer())).writeUtf((org.yatopiamc.yatopia.server.YatopiaConfig.brandName)))); // Yatopia)));
playerconnection.send(new ClientboundChangeDifficultyPacket(worlddata.getDifficulty(), worlddata.isDifficultyLocked()));
playerconnection.send(new ClientboundPlayerAbilitiesPacket(player.getAbilities()));
playerconnection.send(new ClientboundSetCarriedItemPacket(player.getInventory().selected));
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 58b36ed797476f3cec78529e09e913ebb791c5e3..8ff1477e687d53d0634b7763ac1b502d15efcc76 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -393,21 +393,23 @@ public abstract class LivingEntity extends Entity {
this.level.getProfiler().push("livingEntityBaseTick");
boolean flag = this instanceof net.minecraft.world.entity.player.Player;
- if (this.isAlive()) {
- if (this.isInWall()) {
- this.hurt(DamageSource.IN_WALL, 1.0F);
- } else if (flag && !this.level.getWorldBorder().isWithinBounds(this.getBoundingBox())) {
- double d0 = this.level.getWorldBorder().getDistanceToBorder((Entity) this) + this.level.getWorldBorder().getDamageSafeZone();
-
- if (d0 < 0.0D) {
- double d1 = this.level.getWorldBorder().getDamagePerBlock();
-
- if (d1 > 0.0D) {
- this.hurt(DamageSource.IN_WALL, (float) Math.max(1, Mth.floor(-d0 * d1)));
+ if (!org.yatopiamc.yatopia.server.YatopiaConfig.disableEntityStuckChecks) { // Yatopia
+ if (this.isAlive()) {
+ if (this.isInWall()) {
+ this.hurt(DamageSource.IN_WALL, 1.0F);
+ } else if (flag && !this.level.getWorldBorder().isWithinBounds(this.getBoundingBox())) {
+ double d0 = this.level.getWorldBorder().getDistanceToBorder((Entity) this) + this.level.getWorldBorder().getDamageSafeZone();
+
+ if (d0 < 0.0D) {
+ double d1 = this.level.getWorldBorder().getDamagePerBlock();
+
+ if (d1 > 0.0D) {
+ this.hurt(DamageSource.IN_WALL, (float) Math.max(1, Mth.floor(-d0 * d1)));
+ }
}
}
}
- }
+ } // Yatopia
if (this.fireImmune() || this.level.isClientSide) {
this.clearFire();
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 5c85cdb4ef4ffeebdadf01a4ad4a23801bd3fdca..64ad051a445f21ce1c05d8c0200472c1164534b0 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -875,6 +875,7 @@ public final class CraftServer implements Server {
this.playerList.getBans().load();
} catch (IOException ex) {
this.logger.log(Level.WARNING, "Failed to load banned-players.json, " + ex.getMessage());
+ org.yatopiamc.yatopia.server.YatopiaConfig.init((File) console.options.valueOf("yatopia-settings")); // Yatopia
}
org.spigotmc.SpigotConfig.init((File) console.options.valueOf("spigot-settings")); // Spigot
@@ -2373,6 +2374,13 @@ public final class CraftServer implements Server {
org.spigotmc.RestartCommand.restart();
}
+ // Yatopia start
+ @Override
+ public YamlConfiguration getYatopiaConfig() {
+ return org.yatopiamc.yatopia.server.YatopiaConfig.config;
+ }
+ // Yatopia end
+
@Override
public void broadcast(BaseComponent component) {
for (Player player : CraftServer.this.getOnlinePlayers()) {
diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java
index ba01312f7615d0507c1bd1cd175588197f8d122e..c251b053d0a7408df55e31f7730a12a6afc6e0d3 100644
--- a/src/main/java/org/bukkit/craftbukkit/Main.java
+++ b/src/main/java/org/bukkit/craftbukkit/Main.java
@@ -147,6 +147,14 @@ public class Main {
.describedAs("Yml file");
// Paper end
+ // Yatopia start
+ acceptsAll(asList("yatopia", "yatopia-settings"), "File for yatopia settings")
+ .withRequiredArg()
+ .ofType(File.class)
+ .defaultsTo(new File("yatopia.yml"))
+ .describedAs("Yml file");
+ // Yatopia end
+
// Paper start
acceptsAll(asList("server-name"), "Name of the server")
.withRequiredArg()
diff --git a/src/main/java/org/yatopiamc/yatopia/server/YatopiaConfig.java b/src/main/java/org/yatopiamc/yatopia/server/YatopiaConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..eb6786fa040ede035b649d3f9c2c117afe390406
--- /dev/null
+++ b/src/main/java/org/yatopiamc/yatopia/server/YatopiaConfig.java
@@ -0,0 +1,189 @@
+package org.yatopiamc.yatopia.server;
+
+import com.google.common.base.Throwables;
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.logging.Level;
+import java.util.regex.Pattern;
+import org.bukkit.Bukkit;
+import org.bukkit.configuration.InvalidConfigurationException;
+import org.bukkit.configuration.file.YamlConfiguration;
+public class YatopiaConfig {
+ public static File CONFIG_FILE;
+ private static final String HEADER = "This is the main configuration file for Yatopia.\n"
+ + "Yatopia contains many breaking changes and settings, so know what you are doing!\n"
+ + "You have been warned!\n";
+ /*========================================================================*/
+ 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
+ /*========================================================================*/
+
+ public static void init(File configFile) {
+ CONFIG_FILE = configFile;
+ config = new YamlConfiguration();
+ try {
+ config.load(CONFIG_FILE);
+ } catch (IOException ex) {
+ } catch (InvalidConfigurationException ex) {
+ Bukkit.getLogger().log(Level.SEVERE, "Could not load yatopia.yml, please correct your syntax errors", ex);
+ throw Throwables.propagate(ex);
+ }
+ config.options().header(HEADER);
+ config.options().copyDefaults(true);
+ verbose = getBoolean("verbose", false);
+ version = getInt("config-version", 1);
+ set("config-version", 1);
+ removeLeftovers();
+ readConfig(YatopiaConfig.class, null);
+ }
+
+ private static void removeLeftovers() {
+ // this method is only to remove non-used values in the config
+
+ // leftover from rainforest
+ if (config.get("world-settings") != null) {
+ set("world-settings", null);
+ }
+ if (config.get("allow-player-item-duplication") != null) {
+ set("allow-player-item-duplication", null);
+ }
+ if (config.get("allow-ridable-chestable-duping") != null) {
+ set("allow-ridable-chestable-duping", null);
+ }
+ if (config.get("allow-sand-duping") != null) {
+ set("allow-sand-duping", null);
+ }
+ }
+
+ protected static void logError(String s) {
+ Bukkit.getLogger().severe(s);
+ }
+
+ protected static void log(String s) {
+ if (verbose) {
+ Bukkit.getLogger().info(s);
+ }
+ }
+
+ static void readConfig(Class<?> clazz, Object instance) {
+ for (Method method : clazz.getDeclaredMethods()) {
+ if (Modifier.isPrivate(method.getModifiers())) {
+ if (method.getParameterTypes().length == 0 && method.getReturnType() == Void.TYPE) {
+ try {
+ method.setAccessible(true);
+ method.invoke(instance);
+ } catch (InvocationTargetException ex) {
+ throw Throwables.propagate(ex.getCause());
+ } catch (Exception ex) {
+ Bukkit.getLogger().log(Level.SEVERE, "Error invoking " + method, ex);
+ }
+ }
+ }
+ }
+
+ try {
+ config.save(CONFIG_FILE);
+ } catch (IOException ex) {
+ Bukkit.getLogger().log(Level.SEVERE, "Could not save " + CONFIG_FILE, ex);
+ }
+ }
+
+ private static final Pattern SPACE = Pattern.compile(" ");
+ private static final Pattern NOT_NUMERIC = Pattern.compile("[^-\\d.]");
+
+ public static int getSeconds(String str) {
+ str = SPACE.matcher(str).replaceAll("");
+ final char unit = str.charAt(str.length() - 1);
+ str = NOT_NUMERIC.matcher(str).replaceAll("");
+ double num;
+ try {
+ num = Double.parseDouble(str);
+ } catch (Exception e) {
+ num = 0D;
+ }
+ switch (unit) {
+ case 'd':
+ num *= (double) 60 * 60 * 24;
+ break;
+ case 'h':
+ num *= (double) 60 * 60;
+ break;
+ case 'm':
+ num *= 60;
+ break;
+ default:
+ case 's':
+ break;
+ }
+ return (int) num;
+}
+
+ protected static String timeSummary(int seconds) {
+ String time = "";
+
+ if (seconds > 60 * 60 * 24) {
+ time += TimeUnit.SECONDS.toDays(seconds) + "d";
+ seconds %= 60 * 60 * 24;
+ }
+
+ if (seconds > 60 * 60) {
+ time += TimeUnit.SECONDS.toHours(seconds) + "h";
+ seconds %= 60 * 60;
+ }
+
+ if (seconds > 0) {
+ time += TimeUnit.SECONDS.toMinutes(seconds) + "m";
+ }
+ return time;
+}
+
+ private static void set(String path, Object val) {
+ config.set(path, val);
+}
+
+ private static boolean getBoolean(String path, boolean def) {
+ config.addDefault(path, def);
+ return config.getBoolean(path, config.getBoolean(path));
+}
+
+ private static double getDouble(String path, double def) {
+ config.addDefault(path, def);
+ return config.getDouble(path, config.getDouble(path));
+}
+
+ private static float getFloat(String path, float def) {
+ // TODO: Figure out why getFloat() always returns the default value.
+ return (float) getDouble(path, (double) def);
+}
+
+ private static int getInt(String path, int def) {
+ config.addDefault(path, def);
+ return config.getInt(path, config.getInt(path));
+}
+
+ private static <T> List<T> getList(String path, List<T> def) {
+ config.addDefault(path, def);
+ return (List<T>) config.getList(path, config.getList(path));
+}
+
+ private static String getString(String path, String def) {
+ config.addDefault(path, def);
+ return config.getString(path, config.getString(path));
+}
+
+ public static boolean disableEntityStuckChecks = false;
+private static void disableEntityStuckChecks() {
+ disableEntityStuckChecks = getBoolean("settings.disableEntityStuckChecks", false);
+}
+
+ public static String brandName = "Yatopia";
+private static void brandName() {
+ brandName = getString("brand-name", brandName);
+ }
+}
\ No newline at end of file