diff --git a/NachoSpigot-Server/src/main/java/dev/cobblesword/nachospigot/Nacho.java b/NachoSpigot-Server/src/main/java/dev/cobblesword/nachospigot/Nacho.java index eedf0dfe4..517bc4f81 100644 --- a/NachoSpigot-Server/src/main/java/dev/cobblesword/nachospigot/Nacho.java +++ b/NachoSpigot-Server/src/main/java/dev/cobblesword/nachospigot/Nacho.java @@ -1,7 +1,7 @@ package dev.cobblesword.nachospigot; +import me.elier.nachospigot.config.NachoConfig; import xyz.sculas.nacho.anticrash.AntiCrash; -import dev.cobblesword.nachospigot.commons.FileUtils; import xyz.sculas.nacho.async.AsyncExplosions; import xyz.sculas.nacho.patches.RuntimePatches; import dev.cobblesword.nachospigot.protocol.PacketListener; @@ -12,49 +12,30 @@ import com.google.common.collect.Sets; import java.util.Set; -import java.io.File; public class Nacho { private static Nacho INSTANCE; - private static final File CONFIG_FILE = new File("nacho.json"); - private NachoConfig config; - private final Set packetListeners = Sets.newConcurrentHashSet(); private final Set movementListeners = Sets.newConcurrentHashSet(); public Nacho() { INSTANCE = this; - this.config = new NachoConfig(); - while (!CONFIG_FILE.exists()) FileUtils.toFile(this.config, CONFIG_FILE); - this.config = FileUtils.toObject(CONFIG_FILE, NachoConfig.class); - assert this.config != null; - FileUtils.toFile(this.config, CONFIG_FILE); - - AsyncExplosions.initExecutor(config.useFixedPoolForTNT, config.fixedPoolSize); + AsyncExplosions.initExecutor(NachoConfig.useFixedPoolForTNT, NachoConfig.fixedPoolSize); - if(this.config.enableAntiCrash) { + if(NachoConfig.enableAntiCrash) { System.out.println("[NS-AntiCrash] Activating Anti Crash."); Nacho.get().registerPacketListener(new AntiCrash()); System.out.println("[NS-AntiCrash] Activated Anti Crash."); } } - public void reloadConfig() { - this.config = FileUtils.toObject(CONFIG_FILE, NachoConfig.class); - } - public static Nacho get() { return INSTANCE == null ? new Nacho() : INSTANCE; } - public NachoConfig getConfig() - { - return config; - } - public void registerCommands() { SetMaxSlotCommand setMaxSlotCommand = new SetMaxSlotCommand("sms"); //[Nacho-0021] Add setMaxPlayers within Bukkit.getServer() and SetMaxSlot Command SpawnMobCommand spawnMobCommand = new SpawnMobCommand("spawnmob"); diff --git a/NachoSpigot-Server/src/main/java/dev/cobblesword/nachospigot/NachoConfig.java b/NachoSpigot-Server/src/main/java/dev/cobblesword/nachospigot/OldNachoConfig.java similarity index 98% rename from NachoSpigot-Server/src/main/java/dev/cobblesword/nachospigot/NachoConfig.java rename to NachoSpigot-Server/src/main/java/dev/cobblesword/nachospigot/OldNachoConfig.java index cde96c4b8..413ba896c 100644 --- a/NachoSpigot-Server/src/main/java/dev/cobblesword/nachospigot/NachoConfig.java +++ b/NachoSpigot-Server/src/main/java/dev/cobblesword/nachospigot/OldNachoConfig.java @@ -1,6 +1,6 @@ package dev.cobblesword.nachospigot; -public class NachoConfig { +public class OldNachoConfig { public boolean saveEmptyScoreboardTeams = false; public boolean enableVersionCommand = true; public boolean enablePluginsCommand = true; diff --git a/NachoSpigot-Server/src/main/java/dev/cobblesword/nachospigot/protocol/MinecraftPipeline.java b/NachoSpigot-Server/src/main/java/dev/cobblesword/nachospigot/protocol/MinecraftPipeline.java index 0cf878f9c..ded46d9b1 100644 --- a/NachoSpigot-Server/src/main/java/dev/cobblesword/nachospigot/protocol/MinecraftPipeline.java +++ b/NachoSpigot-Server/src/main/java/dev/cobblesword/nachospigot/protocol/MinecraftPipeline.java @@ -4,8 +4,8 @@ import io.netty.channel.*; import io.netty.channel.socket.SocketChannel; import io.netty.handler.timeout.ReadTimeoutHandler; +import me.elier.nachospigot.config.NachoConfig; import net.minecraft.server.*; -import dev.cobblesword.nachospigot.Nacho; public class MinecraftPipeline extends ChannelInitializer { @@ -18,7 +18,7 @@ public MinecraftPipeline(ServerConnection serverConnection) { protected void initChannel(SocketChannel channel) { try { ChannelConfig config = channel.config(); - config.setOption(ChannelOption.TCP_NODELAY, Nacho.get().getConfig().enableTCPNODELAY); + config.setOption(ChannelOption.TCP_NODELAY, NachoConfig.enableTCPNODELAY); config.setOption(ChannelOption.IP_TOS, 0x18); // [Nacho-0027] :: Optimize networking config.setAllocator(ByteBufAllocator.DEFAULT); } catch (Exception ignored) {} diff --git a/NachoSpigot-Server/src/main/java/me/elier/nachospigot/config/NachoConfig.java b/NachoSpigot-Server/src/main/java/me/elier/nachospigot/config/NachoConfig.java new file mode 100644 index 000000000..6dab33115 --- /dev/null +++ b/NachoSpigot-Server/src/main/java/me/elier/nachospigot/config/NachoConfig.java @@ -0,0 +1,312 @@ +package me.elier.nachospigot.config; + +import com.google.common.base.Throwables; +import dev.cobblesword.nachospigot.OldNachoConfig; +import dev.cobblesword.nachospigot.commons.FileUtils; +import org.bukkit.Bukkit; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.YamlConfiguration; +import org.sugarcanemc.sugarcane.util.yaml.YamlCommenter; + +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.nio.file.Files; +import java.util.List; +import java.util.logging.Level; + +public class NachoConfig { + + private static File CONFIG_FILE; + protected static final YamlCommenter c = new YamlCommenter(); + private static final String HEADER = "This is the main configuration file for NachoSpigot.\n" + + "As you can see, there's tons to configure. Some options may impact gameplay, so use\n" + + "with caution, and make sure you know what each option does before configuring.\n" + + "\n" + + "If you need help with the configuration or have any questions related to NachoSpigot,\n" + + "join us in our Discord.\n" + + "\n" + + "Discord: https://discord.gg/SBTEbSx\n" + + "Github: https://github.com/CobbleSword/NachoSpigot\n"; + static YamlConfiguration config; + static int version; + + public static void init(File configFile) { + CONFIG_FILE = configFile; + config = new YamlConfiguration(); + try { + System.out.println("Loading NachoSpigot config from " + configFile.getName()); + config.load(CONFIG_FILE); + } catch (IOException ignored) { + } catch (InvalidConfigurationException ex) { + Bukkit.getLogger().log(Level.SEVERE, "Could not load nacho.yml, please correct your syntax errors", ex); + throw Throwables.propagate(ex); + } + config.options().copyDefaults(true); + File old_config = new File("nacho.json"); + if(old_config.exists()) migrate(old_config); + + int configVersion = 1; // Update this every new configuration update + version = getInt("config-version", configVersion); + set("config-version", configVersion); + readConfig(NachoConfig.class, null); + c.setHeader(HEADER); + c.addComment("config-version", "Configuration version, do NOT modify this!"); + } + + private static void migrate(File old_config) { + OldNachoConfig nachoJson = FileUtils.toObject(old_config, OldNachoConfig.class); + try { + Files.delete(old_config.toPath()); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "Failed to delete nacho.json during migration to nacho.yml"); + throw Throwables.propagate(e); + } + if(nachoJson == null) return; + set("settings.save-empty-scoreboard-teams", nachoJson.saveEmptyScoreboardTeams); + set("settings.commands.enable-version-command", nachoJson.enableVersionCommand); + set("settings.commands.enable-plugins-command", nachoJson.enablePluginsCommand); + set("settings.commands.enable-reload-command", nachoJson.enableReloadCommand); + set("settings.fast-operators", nachoJson.useFastOperators); + set("settings.patch-protocollib", nachoJson.patchProtocolLib); + set("settings.stop-notify-bungee", nachoJson.stopNotifyBungee); + set("settings.anti-malware", nachoJson.checkForMalware); + set("settings.kick-on-illegal-behavior", nachoJson.kickOnIllegalBehavior); + set("world-settings.default.tick-enchantment-tables", nachoJson.shouldTickEnchantmentTables); + set("settings.panda-wire", nachoJson.usePandaWire); + set("world-settings.default.explosions.constant-radius", nachoJson.constantExplosions); + set("world-settings.default.explosions.explode-protected-regions", nachoJson.explosionProtectedRegions); + set("settings.event.fire-entity-explode-event", nachoJson.fireEntityExplodeEvent); + set("world-settings.default.explosions.reduced-density-rays", nachoJson.reducedDensityRays); + set("settings.player-time-statistics-interval", nachoJson.playerTimeStatisticsInterval); + set("settings.brand-name", nachoJson.serverBrandName); + set("settings.stop-decoding-itemstack-on-place", nachoJson.stopDecodingItemStackOnPlace); + set("settings.anti-crash", nachoJson.enableAntiCrash); + set("world-settings.default.infinite-water-sources", nachoJson.infiniteWaterSources); + set("settings.event.fire-leaf-decay-event", nachoJson.leavesDecayEvent); + set("world-settings.default.entity.mob-ai", nachoJson.enableMobAI); + set("world-settings.default.entity.mob-sound", nachoJson.enableMobSound); + set("world-settings.default.entity.entity-activation", nachoJson.enableEntityActivation); + set("world-settings.default.entity.endermite-spawning", nachoJson.endermiteSpawning); + set("world-settings.default.enable-lava-to-cobblestone", nachoJson.enableLavaToCobblestone); + set("settings.event.fire-player-move-event", nachoJson.firePlayerMoveEvent); + set("world-settings.default.physics.disable-place", nachoJson.disablePhysicsPlace); + set("world-settings.default.physics.disable-update", nachoJson.disablePhysicsUpdate); + set("world-settings.default.block-operations", nachoJson.doBlocksOperations); + set("world-settings.default.unload-chunks", nachoJson.doChunkUnload); + set("settings.chunk.threads", nachoJson.chunkThreads); + set("settings.chunk.players-per-thread", nachoJson.playersPerThread); + set("settings.use-tcp-nodelay", nachoJson.enableTCPNODELAY); + set("settings.fixed-pools.use-fixed-pools-for-explosions", nachoJson.useFixedPoolForTNT); + set("settings.fixed-pools.size", nachoJson.fixedPoolSize); + set("settings.faster-cannon-tracker", nachoJson.useFasterCannonTracker); + set("world-settings.default.disable-sponge-absorption", nachoJson.disableSpongeAbsorption); + set("settings.fix-eat-while-running", nachoJson.fixEatWhileRunning); + set("settings.hide-projectiles-from-hidden-players", nachoJson.hideProjectilesFromHiddenPlayers); + } + + 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 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) { + config.addDefault(path, def); + return config.getFloat(path, config.getFloat(path)); + } + + private static int getInt(String path, int def) { + config.addDefault(path, def); + return config.getInt(path, config.getInt(path)); + } + + private static List getList(String path, T def) { + config.addDefault(path, def); + return (List) 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 saveEmptyScoreboardTeams; + + private static void saveEmptyScoreboardTeams() { + saveEmptyScoreboardTeams = getBoolean("settings.save-empty-scoreboard-teams", false); + c.addComment("settings.save-empty-scoreboard-teams", "Toggles whether or not the server should save empty scoreboard teams"); + } + public static boolean enableVersionCommand; + public static boolean enablePluginsCommand; + public static boolean enableReloadCommand; + + private static void commands() { + enableVersionCommand = getBoolean("settings.commands.enable-version-command", true); + c.addComment("settings.commands.enable-version-command", "Toggles the /version command"); + enablePluginsCommand = getBoolean("settings.commands.enable-plugins-command", true); + c.addComment("settings.commands.enable-plugins-command", "Toggles the /plugins command"); + enableReloadCommand = getBoolean("settings.commands.enable-reload-command", true); + c.addComment("settings.commands.enable-reload-command", "Toggles the /reload command"); + } + + public static boolean useFastOperators; + + private static void useFastOperators() { + useFastOperators = getBoolean("settings.fast-operators", false); + c.addComment("settings.fast-operators", "Enables Fast Operators, which uses a faster method for managing operators"); + } + public static boolean patchProtocolLib; + + private static void patchProtocolLib() { + patchProtocolLib = getBoolean("settings.patch-protocollib", true); + c.addComment("settings.patch-protocollib", "Enables the ProtocolLib runtime patch (not required on ProtocolLib version 4.7+)"); + } + public static boolean stopNotifyBungee; + + private static void stopNotifyBungee() { + stopNotifyBungee = getBoolean("settings.stop-notify-bungee", false); + c.addComment("settings.stop-notify-bungee", "Disables the firewall check when running BungeeCord"); + } + public static boolean checkForMalware; + + private static void antiMalware() { + checkForMalware = getBoolean("settings.anti-malware", false); + c.addComment("settings.anti-malware", "Enables the built-in anti malware feature"); + } + + public static boolean kickOnIllegalBehavior; + + private static void kickOnIllegalBehavior() { + kickOnIllegalBehavior = getBoolean("settings.kick-on-illegal-behavior", true); + c.addComment("settings.kick-on-illegal-behavior", "Kicks players if they try to do an illegal action (e.g. using a creative mode action while not in creative mode.)"); + } + + public static boolean usePandaWire; + + private static void usePandaWire() { + usePandaWire = getBoolean("settings.panda-wire", true); + c.addComment("settings.panda-wire", "Optimizes redstone wires."); + } + + public static boolean fireEntityExplodeEvent; + public static boolean firePlayerMoveEvent; + public static boolean leavesDecayEvent; + + private static void fireEntityExplodeEvent() { + fireEntityExplodeEvent = getBoolean("settings.event.fire-entity-explode-event", true); + c.addComment("settings.event.fire-entity-explode-event", "Toggles the entity explode event"); + firePlayerMoveEvent = getBoolean("settings.event.fire-player-move-event", true); + c.addComment("settings.event.fire-player-move-event", "Toggles the player move event"); + leavesDecayEvent = getBoolean("settings.event.fire-leaf-decay-event", true); + c.addComment("settings.event.fire-leaf-decay-event", "Toggles the leaf decay event"); + } + + public static int playerTimeStatisticsInterval; + + private static void playerTimeStatisticsInterval() { + playerTimeStatisticsInterval = getInt("settings.player-time-statistics-interval", 20); + c.addComment("settings.player-time-statistics-interval", "Changes when statistics are ticked (e.g. 20 would be every 20th tick)"); + } + + public static String serverBrandName; + + private static void serverBrandName() { + serverBrandName = getString("settings.brand-name", "NachoSpigot"); + c.addComment("settings.brand-name", "Changes the brand name of the server.\nThis will show in statistics, server lists, client crashes,\n and in the client debug screen. (accessed by pressing F3)"); + } + + public static boolean stopDecodingItemStackOnPlace; + + private static void stopDecodingItemStackOnPlace() { + stopDecodingItemStackOnPlace = getBoolean("settings.stop-decoding-itemstack-on-place", true); + c.addComment("settings.stop-decoding-itemstack-on-place", "Disables decoding itemstacks when not needed"); + } + + public static boolean enableAntiCrash; + + private static void enableAntiCrash() { + enableAntiCrash = getBoolean("settings.anti-crash", true); + c.addComment("settings.anti-crash", "Kicks players if they try to do an action that would/might crash the server"); + } + + public static int chunkThreads; // PaperSpigot - Bumped value + public static int playersPerThread; + + private static void chunk() { + chunkThreads = getInt("settings.chunk.threads", 2); + c.addComment("settings.chunk.threads", "The amount of threads used for chunks"); + playersPerThread = getInt("settings.chunk.players-per-thread", 50); + c.addComment("settings.chunk.players-per-thread", "The amount of players for each thread"); + } + + public static boolean enableTCPNODELAY; + + private static void enableTCPNODELAY() { + enableTCPNODELAY = getBoolean("settings.use-tcp-nodelay", true); + c.addComment("settings.use-tcp-nodelay", "Enables the TCP_NODELAY socket option"); + } + + public static boolean useFixedPoolForTNT; + public static int fixedPoolSize; + + private static void fixedPools() { + useFixedPoolForTNT = getBoolean("settings.fixed-pools.use-fixed-pools-for-explosions", false); + c.addComment("settings.fixed-pools.use-fixed-pools-for-explosions", "Enables fixed thread pool for explosions"); + fixedPoolSize = getInt("settings.fixed-pools.size", 500); + c.addComment("settings.fixed-pools.size", "The size for the fixed thread pool for explosions."); + } + public static boolean useFasterCannonTracker; + + private static void useFasterCannonTracker() { + useFasterCannonTracker = getBoolean("settings.faster-cannon-tracker", true); + c.addComment("settings.faster-cannon-tracker", "Enables a faster cannon entity tracker"); + } + + public static boolean fixEatWhileRunning; + + private static void fixEatWhileRunning() { + fixEatWhileRunning = getBoolean("settings.fix-eat-while-running", false); + c.addComment("settings.fix-eat-while-running", "Fixes the eating while running bug"); + } + + public static boolean hideProjectilesFromHiddenPlayers; + + public static void hideProjectilesFromHiddenPlayers() { + hideProjectilesFromHiddenPlayers = getBoolean("settings.hide-projectiles-from-hidden-players", false); + c.addComment("settings.hide-projectiles-from-hidden-players", "Hides projectiles from hidden players"); + } +} diff --git a/NachoSpigot-Server/src/main/java/me/elier/nachospigot/config/NachoWorldConfig.java b/NachoSpigot-Server/src/main/java/me/elier/nachospigot/config/NachoWorldConfig.java new file mode 100644 index 000000000..b8b1608f2 --- /dev/null +++ b/NachoSpigot-Server/src/main/java/me/elier/nachospigot/config/NachoWorldConfig.java @@ -0,0 +1,151 @@ +package me.elier.nachospigot.config; + +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.util.List; + +public class NachoWorldConfig { + + private final String worldName; + private final YamlConfiguration config; + private boolean verbose; + + public NachoWorldConfig(String worldName) { + this.worldName = worldName; + this.config = NachoConfig.config; + init(); + } + + public void init() { + this.verbose = getBoolean("verbose", false); + + log("-------- World Settings For [\" + worldName + \"] --------"); + NachoConfig.readConfig(NachoWorldConfig.class, this); + } + + private void log(String s) { + if(verbose) { + Bukkit.getLogger().info(s); + } + } + + private void set(String path, Object val) { + config.set("world-settings.default." + path, val); + } + + private boolean getBoolean(String path, boolean def) { + config.addDefault("world-settings.default." + path, def); + return config.getBoolean("world-settings." + worldName + "." + path, config.getBoolean("world-settings.default." + path)); + } + + private double getDouble(String path, double def) { + config.addDefault("world-settings.default." + path, def); + return config.getDouble("world-settings." + worldName + "." + path, config.getDouble("world-settings.default." + path)); + } + + private int getInt(String path, int def) { + config.addDefault("world-settings.default." + path, def); + return config.getInt("world-settings." + worldName + "." + path, config.getInt("world-settings.default." + path)); + } + + private float getFloat(String path, float def) { + config.addDefault("world-settings.default." + path, def); + return config.getFloat("world-settings." + worldName + "." + path, config.getFloat("world-settings.default." + path)); + } + + private List getList(String path, T def) { + config.addDefault("world-settings.default." + path, def); + return (List) config.getList("world-settings." + worldName + "." + path, config.getList("world-settings.default." + path)); + } + + private String getString(String path, String def) { + config.addDefault("world-settings.default." + path, def); + return config.getString("world-settings." + worldName + "." + path, config.getString("world-settings.default." + path)); + } + + private void addComment(String path, String comment) { + NachoConfig.c.addComment("world-settings.default." + path, comment); + } + + public boolean disableSpongeAbsorption; + + private void disableSpongeAbsorption() { + disableSpongeAbsorption = getBoolean("disable-sponge-absorption", false); + addComment("disable-sponge-absorption", "Disables sponge absorption"); + } + + public boolean doChunkUnload; + + private void doChunkUnload() { + doChunkUnload = getBoolean("unload-chunks", true); + addComment("unload-chunks", "Enable unloading chunks"); + } + + public boolean doBlocksOperations; + + private void doBlocksOperations() { + doBlocksOperations = getBoolean("block-operations", true); + addComment("block-operations", "Enable block operations"); + } + + public boolean disablePhysicsPlace; + public boolean disablePhysicsUpdate; + + private void physics() { + disablePhysicsPlace = getBoolean("physics.disable-place", false); + addComment("physics.disable-place", "Disables physics place"); + disablePhysicsUpdate = getBoolean("settings.physics.disable-update", false); + addComment("physics.disable-update", "Disables physics update"); + } + + public boolean enableLavaToCobblestone; + + private void setEnableLavaToCobblestone() { + enableLavaToCobblestone = getBoolean("enable-lava-to-cobblestone", true); + addComment("enable-lava-to-cobblestone", "Enables lava converting to cobblestone."); + } + + public boolean enableMobAI; + public boolean enableMobSound; + public boolean enableEntityActivation; + public boolean endermiteSpawning; + + private void entity() { + enableMobAI = getBoolean("entity.mob-ai", true); + addComment("entity.mob-ai", "Enables mob AI"); + enableMobSound = getBoolean("entity.mob-sound", true); + addComment("entity.mob-sound", "Enables mob sound"); + enableEntityActivation = getBoolean("entity.entity-activation", true); + addComment("entity.entity-activation", "Enables active ticks for entities"); + endermiteSpawning = getBoolean("entity.endermite-spawning", true); + addComment("entity.endermite-spawning", "Enables endermite spawning."); + } + + public boolean infiniteWaterSources; + + private void infiniteWaterSources() { + infiniteWaterSources = getBoolean("infinite-water-sources", true); + addComment("infinite-water-sources", "Enables infinite water sources"); + } + + public boolean constantExplosions; + public boolean explosionProtectedRegions; + public boolean reducedDensityRays; + + private void explosions() { + constantExplosions = getBoolean("explosions.constant-radius", false); + addComment("explosions.constant-explosions", "Changes the radius of explosions to be constant."); + explosionProtectedRegions = getBoolean("explosions.explode-protected-regions", true); + addComment("explosions.explode-protected-regions", "Toggles whether explosions should explode protected regions"); + reducedDensityRays = getBoolean("explosions.reduced-density-rays", true); + addComment("explosions.reduced-density-rays", "Toggles whether the server should use reduced rays when calculating density"); + } + + public boolean shouldTickEnchantmentTables; + + private void shouldTickEnchantmentTables() { + shouldTickEnchantmentTables = getBoolean("tick-enchantment-tables", true); + addComment("tick-enchantment-tables", "Toggles whether enchantment tables should be ticked"); + } +} diff --git a/NachoSpigot-Server/src/main/java/me/elier/util/Utils.java b/NachoSpigot-Server/src/main/java/me/elier/util/Utils.java new file mode 100644 index 000000000..2686edd69 --- /dev/null +++ b/NachoSpigot-Server/src/main/java/me/elier/util/Utils.java @@ -0,0 +1,44 @@ +package me.elier.util; + +import org.apache.commons.lang.reflect.FieldUtils; + +import java.util.Arrays; + +public class Utils { + // from String.repeat in Java 11 + public static String repeat(String string, int count) { + byte[] value = null; + byte coder = 0; + try { + value = (byte[]) FieldUtils.readDeclaredField(string, "value", true); + coder = (byte) FieldUtils.readDeclaredField(string, "coder", true); + } catch (IllegalAccessException ignored) {} + if (count < 0) { + throw new IllegalArgumentException("count is negative: " + count); + } + if (count == 1) { + return string; + } + final int len = value.length; + if (len == 0 || count == 0) { + return ""; + } + if (Integer.MAX_VALUE / count < len) { + throw new OutOfMemoryError("Required length exceeds implementation limit"); + } + if (len == 1) { + final byte[] single = new byte[count]; + Arrays.fill(single, value[0]); + return new String(single, coder); + } + final int limit = len * count; + final byte[] multiple = new byte[limit]; + System.arraycopy(value, 0, multiple, 0, len); + int copied = len; + for (; copied < limit - copied; copied <<= 1) { + System.arraycopy(multiple, 0, multiple, copied, copied); + } + System.arraycopy(multiple, 0, multiple, copied, limit - copied); + return new String(multiple, coder); + } +} diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/Block.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/Block.java index 35b828315..eba818bbe 100644 --- a/NachoSpigot-Server/src/main/java/net/minecraft/server/Block.java +++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/Block.java @@ -1,6 +1,6 @@ package net.minecraft.server; -import dev.cobblesword.nachospigot.Nacho; +import me.elier.nachospigot.config.NachoConfig; import me.suicidalkids.ion.blocks.redstone.PandaRedstoneWire; import java.util.Iterator; @@ -797,7 +797,7 @@ public static void S() { a(52, "mob_spawner", (new BlockMobSpawner()).c(5.0F).a(Block.j).c("mobSpawner").K()); a(53, "oak_stairs", (new BlockStairs(block1.getBlockData().set(BlockWood.VARIANT, BlockWood.EnumLogVariant.OAK))).c("stairsWood")); a(54, "chest", (new BlockChest(0)).c(2.5F).a(Block.f).c("chest")); - a(55, "redstone_wire", (Nacho.get().getConfig().usePandaWire ? new PandaRedstoneWire() : new BlockRedstoneWire()).c(0.0F).a(Block.e).c("redstoneDust").K()); + a(55, "redstone_wire", (NachoConfig.usePandaWire ? new PandaRedstoneWire() : new BlockRedstoneWire()).c(0.0F).a(Block.e).c("redstoneDust").K()); a(56, "diamond_ore", (new BlockOre()).c(3.0F).b(5.0F).a(Block.i).c("oreDiamond")); a(57, "diamond_block", (new Block(Material.ORE, MaterialMapColor.G)).c(5.0F).b(10.0F).a(Block.j).c("blockDiamond").a(CreativeModeTab.b)); a(58, "crafting_table", (new BlockWorkbench()).c(2.5F).a(Block.f).c("workbench")); diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockFalling.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockFalling.java index 50270d91f..728fad210 100644 --- a/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockFalling.java +++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockFalling.java @@ -3,6 +3,8 @@ import java.util.Random; import dev.cobblesword.nachospigot.Nacho; +import me.elier.nachospigot.config.NachoConfig; + public class BlockFalling extends Block { public static boolean instaFall; @@ -17,13 +19,13 @@ public BlockFalling(Material material) { } public void onPlace(World world, BlockPosition blockposition, IBlockData iblockdata) { - if (!Nacho.get().getConfig().disablePhysicsPlace) { + if (!world.nachoSpigotConfig.disablePhysicsPlace) { world.a(blockposition, (Block) this, this.a(world)); } } public void doPhysics(World world, BlockPosition blockposition, IBlockData iblockdata, Block block) { - if (!Nacho.get().getConfig().disablePhysicsUpdate) { + if (!world.nachoSpigotConfig.disablePhysicsUpdate) { world.a(blockposition, (Block) this, this.a(world)); } } diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockFlowing.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockFlowing.java index 833042cf3..4519853f0 100644 --- a/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockFlowing.java +++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockFlowing.java @@ -5,9 +5,8 @@ import java.util.Random; import java.util.Set; -import dev.cobblesword.nachospigot.Nacho; - // CraftBukkit start +import me.elier.nachospigot.config.NachoConfig; import org.bukkit.block.BlockFace; import org.bukkit.event.block.BlockFromToEvent; // CraftBukkit end @@ -66,7 +65,7 @@ public void b(World world, BlockPosition blockposition, IBlockData iblockdata, R } } - if ((Nacho.get().getConfig().infiniteWaterSources) && (this.a >= 2) && (this.material == Material.WATER)) { + if ((world.nachoSpigotConfig.infiniteWaterSources) && (this.a >= 2) && (this.material == Material.WATER)) { IBlockData iblockdata1 = world.getType(blockposition.down()); if (iblockdata1.getBlock().getMaterial().isBuildable()) { @@ -114,7 +113,7 @@ public void b(World world, BlockPosition blockposition, IBlockData iblockdata, R server.getPluginManager().callEvent(event); } if (!event.isCancelled()) { - if ((this.material == Material.LAVA) && (world.getType(blockposition.down()).getBlock().getMaterial() == Material.WATER) && (Nacho.get().getConfig().enableLavaToCobblestone)) { + if ((this.material == Material.LAVA) && (world.getType(blockposition.down()).getBlock().getMaterial() == Material.WATER) && (world.nachoSpigotConfig.enableLavaToCobblestone)) { world.setTypeUpdate(blockposition.down(), Blocks.STONE.getBlockData()); this.fizz(world, blockposition.down()); return; diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockFluids.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockFluids.java index cecd06514..2b6d5aaf2 100644 --- a/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockFluids.java +++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockFluids.java @@ -3,6 +3,7 @@ import dev.cobblesword.nachospigot.commons.Constants; import dev.cobblesword.nachospigot.Nacho; +import me.elier.nachospigot.config.NachoConfig; import java.util.Iterator; import java.util.Random; @@ -149,7 +150,7 @@ public boolean e(World world, BlockPosition blockposition, IBlockData iblockdata } } - if ((flag) && (Nacho.get().getConfig().enableLavaToCobblestone)) { + if ((flag) && (world.nachoSpigotConfig.enableLavaToCobblestone)) { Integer integer = (Integer) iblockdata.get(BlockFluids.LEVEL); if (integer.intValue() == 0) { diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockLeaves.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockLeaves.java index 3e55b3c50..732bee1bb 100644 --- a/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockLeaves.java +++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockLeaves.java @@ -4,6 +4,7 @@ import dev.cobblesword.nachospigot.Nacho; +import me.elier.nachospigot.config.NachoConfig; import org.bukkit.event.block.LeavesDecayEvent; // CraftBukkit public abstract class BlockLeaves extends BlockTransparent { @@ -134,7 +135,7 @@ public void b(World world, BlockPosition blockposition, IBlockData iblockdata, R } private void e(World world, BlockPosition blockposition) { - if (!Nacho.get().getConfig().leavesDecayEvent) { + if (!NachoConfig.leavesDecayEvent) { return; } diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockSponge.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockSponge.java index 3955eb949..541073074 100644 --- a/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockSponge.java +++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockSponge.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; -import dev.cobblesword.nachospigot.Nacho; public class BlockSponge extends Block { @@ -12,7 +11,7 @@ public class BlockSponge extends Block { protected BlockSponge() { super(Material.SPONGE); - this.j(this.blockStateList.getBlockData().set(BlockSponge.WET, Boolean.valueOf(false))); + this.j(this.blockStateList.getBlockData().set(BlockSponge.WET, false)); this.a(CreativeModeTab.b); } @@ -21,17 +20,17 @@ public String getName() { } public int getDropData(IBlockData iblockdata) { - return ((Boolean) iblockdata.get(BlockSponge.WET)).booleanValue() ? 1 : 0; + return iblockdata.get(BlockSponge.WET) ? 1 : 0; } public void onPlace(World world, BlockPosition blockposition, IBlockData iblockdata) { - if (!Nacho.get().getConfig().disableSpongeAbsorption) { + if (!world.nachoSpigotConfig.disableSpongeAbsorption) { this.e(world, blockposition, iblockdata); } } public void doPhysics(World world, BlockPosition blockposition, IBlockData iblockdata, Block block) { - if (!Nacho.get().getConfig().disableSpongeAbsorption) { + if (!world.nachoSpigotConfig.disableSpongeAbsorption) { this.e(world, blockposition, iblockdata); super.doPhysics(world, blockposition, iblockdata, block); } @@ -39,8 +38,8 @@ public void doPhysics(World world, BlockPosition blockposition, IBlockData ibloc } protected void e(World world, BlockPosition blockposition, IBlockData iblockdata) { - if (!Nacho.get().getConfig().disableSpongeAbsorption && !((Boolean) iblockdata.get(BlockSponge.WET)).booleanValue() && this.e(world, blockposition)) { - world.setTypeAndData(blockposition, iblockdata.set(BlockSponge.WET, Boolean.valueOf(true)), 2); + if (!world.nachoSpigotConfig.disableSpongeAbsorption && !(Boolean) iblockdata.get(BlockSponge.WET) && this.e(world, blockposition)) { + world.setTypeAndData(blockposition, iblockdata.set(BlockSponge.WET, true), 2); world.triggerEffect(2001, blockposition, Block.getId(Blocks.WATER)); } @@ -101,6 +100,6 @@ public int toLegacyData(IBlockData iblockdata) { } protected BlockStateList getStateList() { - return new BlockStateList(this, new IBlockState[] { BlockSponge.WET}); + return new BlockStateList(this, BlockSponge.WET); } } diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/ChunkProviderServer.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/ChunkProviderServer.java index a7ff34f7d..a71ccd684 100644 --- a/NachoSpigot-Server/src/main/java/net/minecraft/server/ChunkProviderServer.java +++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/ChunkProviderServer.java @@ -4,6 +4,7 @@ import java.util.Iterator; import java.util.List; import dev.cobblesword.nachospigot.events.ChunkPreLoadEvent; +import me.elier.nachospigot.config.NachoConfig; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; // CraftBukkit start @@ -20,7 +21,6 @@ import it.unimi.dsi.fastutil.longs.LongIterator; import it.unimi.dsi.fastutil.longs.LongSet; // TacoSpigot end -import dev.cobblesword.nachospigot.Nacho; public class ChunkProviderServer implements IChunkProvider { private static final Logger b = LogManager.getLogger(); @@ -52,7 +52,7 @@ public java.util.Collection a() { } public void queueUnload(int i, int j) { - if (!Nacho.get().getConfig().doChunkUnload) { + if (!world.nachoSpigotConfig.doChunkUnload) { return; } diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/DedicatedServer.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/DedicatedServer.java index 2add7f265..5de5dfa7f 100644 --- a/NachoSpigot-Server/src/main/java/net/minecraft/server/DedicatedServer.java +++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/DedicatedServer.java @@ -11,6 +11,7 @@ import dev.cobblesword.nachospigot.Nacho; import dev.cobblesword.nachospigot.commons.IPUtils; import dev.cobblesword.nachospigot.knockback.Knockback; +import me.elier.nachospigot.config.NachoConfig; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -172,7 +173,7 @@ public void run() { this.setPort(this.propertyManager.getInt("server-port", 25565)); } // Spigot start - Nacho.get(); // NachoSpigot - Load config before PlayerList + NachoConfig.init((File) options.valueOf("nacho-settings")); // NachoSpigot - Load config before PlayerList this.a(new DedicatedPlayerList(this)); org.spigotmc.SpigotConfig.init((File) options.valueOf("spigot-settings")); org.spigotmc.SpigotConfig.registerCommands(); @@ -212,9 +213,9 @@ public void run() { if (org.spigotmc.SpigotConfig.bungee) { DedicatedServer.LOGGER.warn("Whilst this makes it possible to use BungeeCord, unless access to your server is properly restricted, it also opens up the ability for hackers to connect with any username they choose."); DedicatedServer.LOGGER.warn("Please see http://www.spigotmc.org/wiki/firewall-guide/ for further information."); - if (!Nacho.get().getConfig().stopNotifyBungee) { + if (!NachoConfig.stopNotifyBungee) { DedicatedServer.LOGGER.warn("---------------------------- NachoSpigot Checker ----------------------------"); - DedicatedServer.LOGGER.warn("If you don't want to see this message anymore, set \"stopNotifyBungee\" to \"true\" in \"nacho.json\"!"); + DedicatedServer.LOGGER.warn("If you don't want to see this message anymore, set \"settings.stop-notify-bungee\" to \"true\" in \"nacho.yml\"!"); DedicatedServer.LOGGER.warn("Checking firewall.."); try { String external = IPUtils.getExternalAddress(); diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/EntityEnderPearl.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/EntityEnderPearl.java index 5e125e428..3fd3512cb 100644 --- a/NachoSpigot-Server/src/main/java/net/minecraft/server/EntityEnderPearl.java +++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/EntityEnderPearl.java @@ -2,9 +2,9 @@ // CraftBukkit start import dev.cobblesword.nachospigot.commons.Constants; +import me.elier.nachospigot.config.NachoConfig; import org.bukkit.Bukkit; import org.github.paperspigot.PaperSpigotConfig; -import net.minecraft.server.BlockPosition; import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.event.player.PlayerTeleportEvent; @@ -82,7 +82,7 @@ protected void a(MovingObjectPosition movingobjectposition) { Bukkit.getPluginManager().callEvent(teleEvent); if (!teleEvent.isCancelled() && !entityplayer.playerConnection.isDisconnected()) { - if ((this.random.nextFloat() < 0.05F) && (this.world.getGameRules().getBoolean("doMobSpawning")) && (Nacho.get().getConfig().endermiteSpawning)) { + if ((this.random.nextFloat() < 0.05F) && (this.world.getGameRules().getBoolean("doMobSpawning")) && (world.nachoSpigotConfig.endermiteSpawning)) { EntityEndermite entityendermite = new EntityEndermite(this.world); entityendermite.a(true); diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/EntityHuman.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/EntityHuman.java index 963636f4c..7a2c84a3f 100644 --- a/NachoSpigot-Server/src/main/java/net/minecraft/server/EntityHuman.java +++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/EntityHuman.java @@ -12,6 +12,7 @@ import dev.cobblesword.nachospigot.Nacho; import dev.cobblesword.nachospigot.knockback.Knockback; import dev.cobblesword.nachospigot.knockback.KnockbackConfig; +import me.elier.nachospigot.config.NachoConfig; import org.bukkit.craftbukkit.entity.CraftHumanEntity; import org.bukkit.craftbukkit.entity.CraftItem; import org.bukkit.craftbukkit.inventory.CraftItemStack; @@ -1346,7 +1347,7 @@ public void setRespawnPosition(BlockPosition blockposition, boolean flag) { } public void b(Statistic statistic) { - this.a(statistic, Nacho.get().getConfig().playerTimeStatisticsInterval); // Nacho / Yatopia - or do it like this :shrug: + this.a(statistic, NachoConfig.playerTimeStatisticsInterval); // Nacho / Yatopia - or do it like this :shrug: } public void a(Statistic statistic, int i) {} diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/EntityInsentient.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/EntityInsentient.java index 8b5a1542c..82194ca3a 100644 --- a/NachoSpigot-Server/src/main/java/net/minecraft/server/EntityInsentient.java +++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/EntityInsentient.java @@ -14,7 +14,6 @@ import org.bukkit.event.entity.EntityUnleashEvent; import org.bukkit.event.entity.EntityUnleashEvent.UnleashReason; // CraftBukkit end -import dev.cobblesword.nachospigot.Nacho; public abstract class EntityInsentient extends EntityLiving { @@ -165,7 +164,7 @@ public int w() { public void x() { String s = this.z(); - if ((s != null) && (Nacho.get().getConfig().enableMobSound)) { + if ((s != null) && (world.nachoSpigotConfig.enableMobSound)) { this.makeSound(s, this.bB(), this.bC()); } @@ -495,7 +494,7 @@ protected final void doTick() { return; } // Spigot End - if (Nacho.get().getConfig().enableMobAI) { + if (world.nachoSpigotConfig.enableMobAI) { this.world.methodProfiler.a("sensing"); this.bk.a(); this.world.methodProfiler.b(); diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/EntityTracker.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/EntityTracker.java index c1cbe7fbc..94ba3d1d5 100644 --- a/NachoSpigot-Server/src/main/java/net/minecraft/server/EntityTracker.java +++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/EntityTracker.java @@ -5,7 +5,7 @@ import java.util.*; import java.util.concurrent.Callable; -import dev.cobblesword.nachospigot.Nacho; +import me.elier.nachospigot.config.NachoConfig; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -147,7 +147,7 @@ public Object call() throws Exception { // IonSpigot start private EntityTrackerEntry createTracker(Entity entity, int i, int j, boolean flag) { - if (entity.isCannoningEntity && Nacho.get().getConfig().useFasterCannonTracker) { + if (entity.isCannoningEntity && NachoConfig.useFasterCannonTracker) { return new me.suicidalkids.ion.visuals.CannonTrackerEntry(entity, i, j, flag); } else { return new EntityTrackerEntry(entity, i, j, flag); diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/Explosion.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/Explosion.java index 85c0edcf9..b316ebbef 100644 --- a/NachoSpigot-Server/src/main/java/net/minecraft/server/Explosion.java +++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/Explosion.java @@ -7,8 +7,8 @@ import java.util.concurrent.CompletableFuture; // CraftBukkit start -import dev.cobblesword.nachospigot.Nacho; import dev.cobblesword.nachospigot.commons.Constants; +import me.elier.nachospigot.config.NachoConfig; import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.Location; @@ -61,7 +61,7 @@ public void a() { if (!this.world.tacoSpigotConfig.optimizeLiquidExplosions || !b.getMaterial().isLiquid()) { // TacoSpigot - skip calculating what blocks to blow up in water/lava boolean protection = false; - if ((Nacho.get().getConfig().fireEntityExplodeEvent || Nacho.get().getConfig().explosionProtectedRegions) && source != null) { + if ((NachoConfig.fireEntityExplodeEvent || world.nachoSpigotConfig.explosionProtectedRegions) && source != null) { Location location = new Location(world.getWorld(), posX, posY, posZ); List list = new java.util.ArrayList<>(1); @@ -349,7 +349,7 @@ private void searchForBlocks(it.unimi.dsi.fastutil.longs.LongSet set, Chunk chun double d1 = vector[1]; double d2 = vector[2]; - float f = this.size * (0.7F + (Nacho.get().getConfig().constantExplosions ? 0.7F : this.world.random.nextFloat()) * 0.6F); + float f = this.size * (0.7F + (world.nachoSpigotConfig.constantExplosions ? 0.7F : this.world.random.nextFloat()) * 0.6F); float resistance = 0; double stepX = this.posX; @@ -410,7 +410,7 @@ private CompletableFuture getBlockDensity(Vec3D vec3d, Entity entity) { } private float calculateDensity(Vec3D vec3d, AxisAlignedBB aabb) { - if (Nacho.get().getConfig().reducedDensityRays) { + if (world.nachoSpigotConfig.reducedDensityRays) { return calculateDensityReducedRays(vec3d, aabb); } else { return this.world.a(vec3d, aabb); diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/MinecraftServer.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/MinecraftServer.java index 43d29c720..756f2c0ca 100644 --- a/NachoSpigot-Server/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/MinecraftServer.java @@ -35,6 +35,7 @@ import javax.imageio.ImageIO; import io.netty.util.ResourceLeakDetector; +import me.elier.nachospigot.config.NachoConfig; import org.apache.commons.lang3.Validate; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -1117,7 +1118,7 @@ public void h(String s) { } public String getServerModName() { - return Nacho.get().getConfig().serverBrandName; // [Nacho-0035] // NachoSpigot - NachoSpigot > // TacoSpigot - TacoSpigot // PaperSpigot - PaperSpigot > // Spigot - Spigot > // CraftBukkit - cb > vanilla! + return NachoConfig.serverBrandName; // [Nacho-0035] // NachoSpigot - NachoSpigot > // TacoSpigot - TacoSpigot // PaperSpigot - PaperSpigot > // Spigot - Spigot > // CraftBukkit - cb > vanilla! } public CrashReport b(CrashReport crashreport) { diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/PacketPlayInBlockPlace.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/PacketPlayInBlockPlace.java index 9b3506638..6a334078a 100644 --- a/NachoSpigot-Server/src/main/java/net/minecraft/server/PacketPlayInBlockPlace.java +++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/PacketPlayInBlockPlace.java @@ -1,7 +1,7 @@ package net.minecraft.server; -import dev.cobblesword.nachospigot.Nacho; import io.netty.handler.codec.DecoderException; +import me.elier.nachospigot.config.NachoConfig; import java.io.IOException; @@ -39,7 +39,7 @@ public void a(PacketDataSerializer packetdataserializer) throws IOException { // KigPaper-0172 start - don't parse itemstack - if (!Nacho.get().getConfig().stopDecodingItemStackOnPlace) { + if (!NachoConfig.stopDecodingItemStackOnPlace) { this.d = packetdataserializer.decodeItemStack(); } else { // Consume everything and leave 3 bytes at the end diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/PersistentScoreboard.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/PersistentScoreboard.java index 682437785..ef31458b3 100644 --- a/NachoSpigot-Server/src/main/java/net/minecraft/server/PersistentScoreboard.java +++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/PersistentScoreboard.java @@ -3,7 +3,7 @@ import java.util.Collection; import java.util.Iterator; -import dev.cobblesword.nachospigot.Nacho; +import me.elier.nachospigot.config.NachoConfig; import net.minecraft.server.IScoreboardCriteria.EnumScoreboardHealthDisplay; import net.minecraft.server.ScoreboardTeamBase.EnumNameTagVisibility; import org.apache.logging.log4j.LogManager; @@ -168,7 +168,7 @@ protected NBTTagList a() { while(var3.hasNext()) { ScoreboardTeam scoreboardteam = (ScoreboardTeam)var3.next(); - if (!Nacho.get().getConfig().saveEmptyScoreboardTeams && scoreboardteam.getPlayerNameSet().isEmpty()) continue; // Paper + if (!NachoConfig.saveEmptyScoreboardTeams && scoreboardteam.getPlayerNameSet().isEmpty()) continue; // Paper NBTTagCompound nbttagcompound = new NBTTagCompound(); nbttagcompound.setString("Name", scoreboardteam.getName()); nbttagcompound.setString("DisplayName", scoreboardteam.getDisplayName()); diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/PlayerConnection.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/PlayerConnection.java index 2ff672a24..783c82c57 100644 --- a/NachoSpigot-Server/src/main/java/net/minecraft/server/PlayerConnection.java +++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/PlayerConnection.java @@ -16,6 +16,8 @@ import java.util.List; import java.util.Set; import java.util.concurrent.Callable; + +import me.elier.nachospigot.config.NachoConfig; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -385,7 +387,7 @@ public void a(PacketPlayInFlying packetplayinflying) { this.lastPitch = to.getPitch(); // Skip the first time we do this - if (Nacho.get().getConfig().firePlayerMoveEvent) { // Spigot - don't skip any move events + if (NachoConfig.firePlayerMoveEvent) { // Spigot - don't skip any move events Location oldTo = to.clone(); PlayerMoveEvent event = new PlayerMoveEvent(player, from, to); this.server.getPluginManager().callEvent(event); @@ -888,7 +890,7 @@ else if (itemstack.getItem() == Items.BUCKET) // SportPaper end } else{ - if(MinecraftServer.currentTick - lastDropTick > 1 && Nacho.get().getConfig().fixEatWhileRunning) this.player.playerInteractManager.useItem(this.player, this.player.world, itemstack); + if(MinecraftServer.currentTick - lastDropTick > 1 && NachoConfig.fixEatWhileRunning) this.player.playerInteractManager.useItem(this.player, this.player.world, itemstack); } // Spigot end @@ -943,7 +945,7 @@ else if (itemstack.getItem() == Items.BUCKET) // CraftBukkit - TODO CHECK IF NEEDED -- new if structure might not need 'always'. Kept it in for now, but may be able to remove in future // KigPaper-0172 if ( - Nacho.get().getConfig().stopDecodingItemStackOnPlace ? ( + NachoConfig.stopDecodingItemStackOnPlace ? ( !ItemStack.matches(this.player.inventory.getItemInHand(), itemstack) || always // KigPaper - use saved itemstack instead of stack from packet ) : (!ItemStack.matches(this.player.inventory.getItemInHand(), packetplayinblockplace.getItemStack()) || always) @@ -2040,7 +2042,7 @@ public void a(PacketPlayInSetCreativeSlot packetplayinsetcreativeslot) { entityitem.j(); } } - } else if (Nacho.get().getConfig().kickOnIllegalBehavior) { + } else if (NachoConfig.kickOnIllegalBehavior) { PlayerIllegalBehaviourEvent event = new PlayerIllegalBehaviourEvent( this.server.getPlayer(this.player), PlayerIllegalBehaviourEvent.IllegalType.CREATIVE_ACTION_NOT_IN_CREATIVE diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/PlayerList.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/PlayerList.java index afdc7272e..a78745812 100644 --- a/NachoSpigot-Server/src/main/java/net/minecraft/server/PlayerList.java +++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/PlayerList.java @@ -12,6 +12,7 @@ import java.text.SimpleDateFormat; import java.util.*; +import me.elier.nachospigot.config.NachoConfig; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -76,7 +77,7 @@ public PlayerList(MinecraftServer minecraftserver) { this.l = new IpBanList(PlayerList.b); this.operators = new OpList(PlayerList.c); // [Nacho-0037] Add toggle for "Faster Operator" - if(Nacho.get().getConfig().useFastOperators) { + if(NachoConfig.useFastOperators) { for (OpListEntry value : this.operators.getValues()) { this.fastOperator.add(value.getKey().getId()); } @@ -1010,7 +1011,7 @@ public IpBanList getIPBans() { public void addOp(GameProfile gameprofile) { this.operators.add(new OpListEntry(gameprofile, this.server.p(), this.operators.b(gameprofile))); // [Nacho-0037] Add toggle for "Faster Operator" - if(Nacho.get().getConfig().useFastOperators) { + if(NachoConfig.useFastOperators) { this.fastOperator.add(gameprofile.getId()); } // CraftBukkit start @@ -1024,7 +1025,7 @@ public void addOp(GameProfile gameprofile) { public void removeOp(GameProfile gameprofile) { this.operators.remove(gameprofile); // [Nacho-0037] Add toggle for "Faster Operator" - if(Nacho.get().getConfig().useFastOperators) { + if(NachoConfig.useFastOperators) { this.fastOperator.remove(gameprofile.getId()); } @@ -1038,12 +1039,12 @@ public void removeOp(GameProfile gameprofile) { public boolean isWhitelisted(GameProfile gameprofile) { // [Nacho-0037] Add toggle for "Faster Operator" - return !this.hasWhitelist || (Nacho.get().getConfig().useFastOperators ? this.fastOperator.contains(gameprofile.getId()) : this.operators.d(gameprofile)) || this.whitelist.d(gameprofile); + return !this.hasWhitelist || (NachoConfig.useFastOperators ? this.fastOperator.contains(gameprofile.getId()) : this.operators.d(gameprofile)) || this.whitelist.d(gameprofile); } public boolean isOp(GameProfile gameprofile) { // [Nacho-0037] Add toggle for "Faster Operator" - return (Nacho.get().getConfig().useFastOperators ? this.fastOperator.contains(gameprofile.getId()) : this.operators.d(gameprofile)) || this.server.T() && this.server.worlds.get(0).getWorldData().v() && this.server.S().equalsIgnoreCase(gameprofile.getName()) || this.t; // CraftBukkit + return (NachoConfig.useFastOperators ? this.fastOperator.contains(gameprofile.getId()) : this.operators.d(gameprofile)) || this.server.T() && this.server.worlds.get(0).getWorldData().v() && this.server.S().equalsIgnoreCase(gameprofile.getName()) || this.t; // CraftBukkit } public EntityPlayer getPlayer(String s) { diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/TileEntityEnchantTable.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/TileEntityEnchantTable.java index a759e31f9..4ceb42705 100644 --- a/NachoSpigot-Server/src/main/java/net/minecraft/server/TileEntityEnchantTable.java +++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/TileEntityEnchantTable.java @@ -1,7 +1,6 @@ package net.minecraft.server; -import dev.cobblesword.nachospigot.Nacho; -import dev.cobblesword.nachospigot.NachoConfig; +import me.elier.nachospigot.config.NachoConfig; import java.util.Random; @@ -40,7 +39,7 @@ public void a(NBTTagCompound var1) { public void c() { // Nacho-0050 - Don't tick Enchantment tables - if(!Nacho.get().getConfig().shouldTickEnchantmentTables) + if(!world.nachoSpigotConfig.shouldTickEnchantmentTables) { return; } diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/World.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/World.java index 271982855..acf28ca4b 100644 --- a/NachoSpigot-Server/src/main/java/net/minecraft/server/World.java +++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/World.java @@ -4,6 +4,8 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; +import me.elier.nachospigot.config.NachoConfig; +import me.elier.nachospigot.config.NachoWorldConfig; import me.suicidalkids.ion.movement.MovementCache; import org.bukkit.Bukkit; import org.bukkit.block.BlockState; @@ -12,19 +14,15 @@ import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.craftbukkit.util.CraftMagicNumbers; -import org.bukkit.craftbukkit.util.LongHashSet; import org.bukkit.entity.Player; import org.bukkit.event.block.BlockCanBuildEvent; import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.generator.ChunkGenerator; -import co.aikar.timings.SpigotTimings; import java.util.*; import java.util.concurrent.Callable; -import dev.cobblesword.nachospigot.Nacho; - // PaperSpigot start import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -177,7 +175,8 @@ public static int keyToZ(long k) public final org.github.paperspigot.PaperSpigotWorldConfig paperSpigotConfig; // PaperSpigot public final co.aikar.timings.WorldTimingsHandler timings; // Spigot - public final net.techcable.tacospigot.TacoSpigotWorldConfig tacoSpigotConfig; + public final net.techcable.tacospigot.TacoSpigotWorldConfig tacoSpigotConfig; // TacoSpigot + public final NachoWorldConfig nachoSpigotConfig; // NachoSpigot public CraftWorld getWorld() { return this.world; @@ -195,6 +194,7 @@ protected World(IDataManager idatamanager, WorldData worlddata, WorldProvider wo this.spigotConfig = new org.spigotmc.SpigotWorldConfig( worlddata.getName() ); // Spigot this.paperSpigotConfig = new org.github.paperspigot.PaperSpigotWorldConfig( worlddata.getName() ); // PaperSpigot this.tacoSpigotConfig = new net.techcable.tacospigot.TacoSpigotWorldConfig(worlddata.getName()); // TacoSpigot + this.nachoSpigotConfig = new NachoWorldConfig(worlddata.getName()); // NachoSpigot this.generator = gen; this.world = new CraftWorld((WorldServer) this, gen, env); this.ticksPerAnimalSpawns = this.getServer().getTicksPerAnimalSpawns(); // CraftBukkit @@ -1852,7 +1852,7 @@ public void entityJoinedWorld(Entity entity, boolean flag) { byte b0 = 32; // Spigot start - if ((!org.spigotmc.ActivationRange.checkIfActive(entity)) && (Nacho.get().getConfig().enableEntityActivation)) { + if ((!org.spigotmc.ActivationRange.checkIfActive(entity)) && (nachoSpigotConfig.enableEntityActivation)) { entity.ticksLived++; entity.inactiveTick(); // PaperSpigot start - Remove entities in unloaded chunks diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/WorldServer.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/WorldServer.java index 7459bae0f..533e1292e 100644 --- a/NachoSpigot-Server/src/main/java/net/minecraft/server/WorldServer.java +++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/WorldServer.java @@ -3,16 +3,15 @@ import com.google.common.base.Predicate; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.google.common.collect.Sets; import com.google.common.util.concurrent.ListenableFuture; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Random; -import java.util.Set; -import java.util.TreeSet; import java.util.UUID; + +import me.elier.nachospigot.config.NachoConfig; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -28,7 +27,6 @@ import org.bukkit.event.block.BlockFormEvent; import org.bukkit.event.weather.LightningStrikeEvent; // CraftBukkit end -import dev.cobblesword.nachospigot.Nacho; public class WorldServer extends World implements IAsyncTaskHandler { @@ -230,7 +228,7 @@ public void doTick() { // CraftBukkit end } // CraftBukkit end - if (Nacho.get().getConfig().doChunkUnload) { + if (this.nachoSpigotConfig.doChunkUnload) { timings.doChunkUnload.startTiming(); // Spigot this.methodProfiler.c("chunkSource"); @@ -477,7 +475,7 @@ protected void h() { } } - if (Nacho.get().getConfig().doBlocksOperations) { + if (this.nachoSpigotConfig.doBlocksOperations) { this.methodProfiler.c("tickBlocks"); timings.chunkTicksBlocks.startTiming(); // Spigot int randomTickSpeed = this.getGameRules().c("randomTickSpeed"); diff --git a/NachoSpigot-Server/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/NachoSpigot-Server/src/main/java/org/bukkit/craftbukkit/CraftServer.java index e2cd06798..df8068275 100644 --- a/NachoSpigot-Server/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/NachoSpigot-Server/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -22,6 +22,7 @@ import com.eatthepath.uuid.FastUUID; import dev.cobblesword.nachospigot.Nacho; import dev.cobblesword.nachospigot.knockback.Knockback; +import me.elier.nachospigot.config.NachoConfig; import org.bukkit.craftbukkit.inventory.*; import xyz.sculas.nacho.malware.AntiMalware; import xyz.sculas.nacho.patches.RuntimePatches; @@ -243,7 +244,7 @@ public CraftServer(MinecraftServer console, PlayerList playerList) { // enablePlugins(PluginLoadOrder.STARTUP); // Spigot End - this.serverName = Nacho.get().getConfig().serverBrandName; + this.serverName = NachoConfig.serverBrandName; } public boolean getCommandBlockOverride(String command) { @@ -284,13 +285,13 @@ public void loadPlugins() { for (Plugin plugin : plugins) { try { // Nacho start - [Nacho-0047] Little anti-malware - if (Nacho.get().getConfig().checkForMalware) { + if (NachoConfig.checkForMalware) { AntiMalware.find(plugin); } // Nacho end String message = String.format("Loading %s", plugin.getDescription().getFullName()); // Nacho start - [Nacho-0043] Fix ProtocolLib - if(plugin.getDescription().getFullName().contains("ProtocolLib") && Nacho.get().getConfig().patchProtocolLib) { + if(plugin.getDescription().getFullName().contains("ProtocolLib") && NachoConfig.patchProtocolLib) { boolean val = RuntimePatches.applyProtocolLibPatch(plugin).join(); if(val) { Logger.getLogger(CraftServer.class.getName()).log(Level.INFO, "Callback returned a good state, ProtocolLib patch was successful and ProtocolLib is now loading."); @@ -735,7 +736,8 @@ public void reload() { org.spigotmc.SpigotConfig.init((File) console.options.valueOf("spigot-settings")); // Spigot org.github.paperspigot.PaperSpigotConfig.init((File) console.options.valueOf("paper-settings")); // PaperSpigot net.techcable.tacospigot.TacoSpigotConfig.init((File) console.options.valueOf("taco-settings")); // TacoSpigot - if(Nacho.get() == null) new Nacho(); + NachoConfig.init((File) console.options.valueOf("nacho-settings")); // NachoSpigot + Nacho.get(); // NachoSpigot for (WorldServer world : console.worlds) { world.worldData.setDifficulty(difficulty); world.setSpawnFlags(monsters, animals); @@ -1579,17 +1581,17 @@ public ConsoleCommandSender getConsoleSender() { @Override public boolean versionCommandEnabled() { - return Nacho.get().getConfig().enableVersionCommand; + return NachoConfig.enableVersionCommand; } @Override public boolean reloadCommandEnabled() { - return Nacho.get().getConfig().enableReloadCommand; + return NachoConfig.enableReloadCommand; } @Override public boolean pluginsCommandEnabled() { - return Nacho.get().getConfig().enablePluginsCommand; + return NachoConfig.enablePluginsCommand; } public EntityMetadataStore getEntityMetadata() { diff --git a/NachoSpigot-Server/src/main/java/org/bukkit/craftbukkit/Main.java b/NachoSpigot-Server/src/main/java/org/bukkit/craftbukkit/Main.java index 82409b8ec..5e1fba31e 100644 --- a/NachoSpigot-Server/src/main/java/org/bukkit/craftbukkit/Main.java +++ b/NachoSpigot-Server/src/main/java/org/bukkit/craftbukkit/Main.java @@ -134,7 +134,7 @@ public static void main(String[] args) { // Spigot End // PaperSpigot Start - acceptsAll(asList("paper", "paper-settings"), "File for paperspigot settings") + acceptsAll(asList("paper", "paper-settings"), "File for paper settings") .withRequiredArg() .ofType(File.class) .defaultsTo(new File("paper.yml")) @@ -148,6 +148,13 @@ public static void main(String[] args) { .defaultsTo(new File("taco.yml")) .describedAs("Yml file"); // TacoSpigot end + // NachoSpigot start + acceptsAll(asList("nacho", "nacho-settings"), "File for nachospigot settings") + .withRequiredArg() + .ofType(File.class) + .defaultsTo(new File("nacho.yml")) + .describedAs("Yml file"); + // NachoSpigot end } }; diff --git a/NachoSpigot-Server/src/main/java/org/bukkit/craftbukkit/chunkio/ChunkIOExecutor.java b/NachoSpigot-Server/src/main/java/org/bukkit/craftbukkit/chunkio/ChunkIOExecutor.java index f527f5dde..dcbba288b 100644 --- a/NachoSpigot-Server/src/main/java/org/bukkit/craftbukkit/chunkio/ChunkIOExecutor.java +++ b/NachoSpigot-Server/src/main/java/org/bukkit/craftbukkit/chunkio/ChunkIOExecutor.java @@ -1,15 +1,15 @@ package org.bukkit.craftbukkit.chunkio; +import me.elier.nachospigot.config.NachoConfig; import net.minecraft.server.Chunk; import net.minecraft.server.ChunkProviderServer; import net.minecraft.server.ChunkRegionLoader; import net.minecraft.server.World; import org.bukkit.craftbukkit.util.AsynchronousExecutor; -import dev.cobblesword.nachospigot.Nacho; public class ChunkIOExecutor { - static final int BASE_THREADS = Nacho.get().getConfig().chunkThreads; - static final int PLAYERS_PER_THREAD = Nacho.get().getConfig().playersPerThread; + static final int BASE_THREADS = NachoConfig.chunkThreads; + static final int PLAYERS_PER_THREAD = NachoConfig.playersPerThread; private static final AsynchronousExecutor instance = new AsynchronousExecutor(new ChunkIOProvider(), BASE_THREADS); diff --git a/NachoSpigot-Server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/NachoSpigot-Server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 7a301b553..4782a625e 100644 --- a/NachoSpigot-Server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/NachoSpigot-Server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -3,7 +3,6 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import com.mojang.authlib.GameProfile; -import dev.cobblesword.nachospigot.Nacho; import dev.cobblesword.nachospigot.commons.Constants; import io.netty.buffer.Unpooled; @@ -15,6 +14,8 @@ import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; + +import me.elier.nachospigot.config.NachoConfig; import net.md_5.bungee.api.chat.BaseComponent; import net.minecraft.server.*; @@ -1016,7 +1017,7 @@ public boolean canSee(org.bukkit.entity.Entity entity) { } // Projectiles from hidden players - if(Nacho.get().getConfig().hideProjectilesFromHiddenPlayers) { + if(NachoConfig.hideProjectilesFromHiddenPlayers) { if (nmsEntity instanceof EntityProjectile) { EntityProjectile entityProjectile = (EntityProjectile) nmsEntity; diff --git a/NachoSpigot-Server/src/main/java/org/sugarcanemc/sugarcane/util/yaml/YamlCommenter.java b/NachoSpigot-Server/src/main/java/org/sugarcanemc/sugarcane/util/yaml/YamlCommenter.java new file mode 100644 index 000000000..8b97df7f6 --- /dev/null +++ b/NachoSpigot-Server/src/main/java/org/sugarcanemc/sugarcane/util/yaml/YamlCommenter.java @@ -0,0 +1,67 @@ +package org.sugarcanemc.sugarcane.util.yaml; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import me.elier.util.Utils; + +public class YamlCommenter { + private final HashMap comments = new HashMap<>(); + private String Header = ""; + + /** + * Add comment to a config option.
+ * Supports multiline comments! + * + * @param path Config path to add comment to + * @param comment Comment to add + */ + public void addComment(String path, String comment) { + comments.put(path, comment); + } + + /** + * Set the header for this config file + * + * @param header Header to add + */ + public void setHeader(String header) { + Header = header; + } + + /** + * Saves comments to config file + * + * @param file File to save to + * @throws IOException + */ + public void saveComments(File file) throws IOException { + ArrayList lines = (ArrayList) Files.readAllLines(file.toPath()); + lines.removeIf(s -> s.trim().startsWith("#") || s.trim().length() <= 4); + lines.add(0, "# " + Header.replace("\n", "\n# ") + "\n"); + for (Map.Entry _comment : comments.entrySet()) { + int line = YamlUtils.findKey(lines, _comment.getKey()); + String prefix = Utils.repeat(" ", getIndentation(lines.get(line))) + "# "; + boolean noNewline = getIndentation(lines.get(line)) > getIndentation(lines.get(line - 1)); + if (line >= 0) + lines.add(line, (noNewline ?"":"\n") + prefix + _comment.getValue().replace("\n", "\n" + prefix)); + else System.out.printf("Failed to find key %s in %s!", _comment.getKey(), file); + } + String text = String.join("\n", lines); + FileWriter fw = new FileWriter(file); + fw.write(text); + fw.close(); + } + + private int getIndentation(String s){ + if(!s.startsWith(" ")) return 0; + int i = 0; + while((s = s.replaceFirst(" ", "")).startsWith(" ")) i++; + return i+1; + } +} \ No newline at end of file diff --git a/NachoSpigot-Server/src/main/java/org/sugarcanemc/sugarcane/util/yaml/YamlUtils.java b/NachoSpigot-Server/src/main/java/org/sugarcanemc/sugarcane/util/yaml/YamlUtils.java new file mode 100644 index 000000000..9601cf75b --- /dev/null +++ b/NachoSpigot-Server/src/main/java/org/sugarcanemc/sugarcane/util/yaml/YamlUtils.java @@ -0,0 +1,25 @@ +package org.sugarcanemc.sugarcane.util.yaml; + +import java.util.ArrayList; +import java.util.List; + +public class YamlUtils { + public static int findKey(List lines, String key) { + String[] parts = key.split("\\."); + int _line = 0; + int indent = 0; + List _cpath = new ArrayList<>(); + for (String part : parts) { + _cpath.add(part); + for (int i = _line; i < lines.size(); i++) { + if (lines.get(i).trim().startsWith(part)) { + _line = i; + if (String.join(".", _cpath).equals(key)) { + return _line; + } + } + } + } + return -1; + } +} diff --git a/NachoSpigot-Server/src/main/java/xyz/sculas/nacho/patches/RuntimePatches.java b/NachoSpigot-Server/src/main/java/xyz/sculas/nacho/patches/RuntimePatches.java index 9bef561fb..2afeed7cc 100644 --- a/NachoSpigot-Server/src/main/java/xyz/sculas/nacho/patches/RuntimePatches.java +++ b/NachoSpigot-Server/src/main/java/xyz/sculas/nacho/patches/RuntimePatches.java @@ -1,7 +1,7 @@ package xyz.sculas.nacho.patches; -import dev.cobblesword.nachospigot.Nacho; import javassist.*; +import me.elier.nachospigot.config.NachoConfig; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.plugin.Plugin; @@ -17,7 +17,7 @@ public class RuntimePatches public static void applyViaVersionBlockPatch() { try { - final String name = Nacho.get().getConfig().serverBrandName.toLowerCase(); + final String name = NachoConfig.serverBrandName.toLowerCase(); if( Bukkit.getPluginManager().isPluginEnabled("ViaVersion") && !name.contains("paper") && @@ -63,7 +63,7 @@ public static void applyViaVersionBlockPatch() { } } catch (Exception e) { logger.warning("Could not patch block placement. Setting brand name to TacoSpigot to make it work properly."); - Nacho.get().getConfig().serverBrandName = "TacoSpigot"; + NachoConfig.serverBrandName = "TacoSpigot"; e.printStackTrace(); } } diff --git a/NachoSpigot-Server/src/test/java/me/elier/nachospigot/config/ConfigurationTests.java b/NachoSpigot-Server/src/test/java/me/elier/nachospigot/config/ConfigurationTests.java new file mode 100644 index 000000000..ce5ef85b6 --- /dev/null +++ b/NachoSpigot-Server/src/test/java/me/elier/nachospigot/config/ConfigurationTests.java @@ -0,0 +1,40 @@ +package me.elier.nachospigot.config; + +import dev.cobblesword.nachospigot.OldNachoConfig; +import dev.cobblesword.nachospigot.commons.FileUtils; +import org.junit.Test; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +public class ConfigurationTests { + + @Test + public void migrateFullConfig() { + FileUtils.toFile(new OldNachoConfig(), new File("nacho.json")); + NachoConfig.init(new File("nacho.yml")); + } + + @Test + public void migratePartialModifiedConfig() throws IOException { + File file = new File("nacho.json"); + file.createNewFile(); + FileWriter writer = new FileWriter(file); + writer.write("{ \"usePandaWire\": false }"); + writer.close(); + NachoConfig.init(new File("nacho.yml")); + assert !NachoConfig.usePandaWire; + } + + @Test + public void migrateEmptyConfig() throws IOException { + new File("nacho.json").createNewFile(); + NachoConfig.init(new File("nacho.yml")); + } + + @Test + public void loadConfig() { + NachoConfig.init(new File("nacho.yml")); + } +} diff --git a/README.md b/README.md index 27a4fbc4d..012004cd6 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ See: [Contributors Page](https://github.com/CobbleSword/NachoSpigot/graphs/contr <--> by Sculas [Nacho-0034] Remove Java 8 message from TacoSpigot which made it so you couldn't run Java 8 or higher -[Nacho-0035] Made it so you can switch the brand name in nacho.json +[Nacho-0035] Made it so you can switch the brand name in nacho.yml [Nacho-0036] Add toggles for commands "reload", "version" and "plugins" [Nacho-0037] Add toggle for "Faster Operator" [Nacho-0039] Fixed a bug in Netty's epoll when using Windows @@ -139,6 +139,7 @@ See: [Contributors Page](https://github.com/CobbleSword/NachoSpigot/graphs/contr [IonSpigot-0014] Faster Chunk Entity List [IonSpigot-0020] Faster EntityTracker Collections [IonSpigot-0035] Optimise Entity Collisions +[IonSpigot-0037] Fast Cannon Entity Tracker [InsanePaper-269] Cache Chunk Coordinations [InsanePaper-390] Heavily optimize Tuinity controlled flush patch @@ -183,4 +184,6 @@ See: [Contributors Page](https://github.com/CobbleSword/NachoSpigot/graphs/contr [MineTick-0017] Fix Insane Nether Portal Lag [Migot-0009] Prevent Creature Spawning in Unloaded Chunks + +[Sugarcane-0022] Add YAML comments ```