Skip to content
This repository has been archived by the owner on May 29, 2022. It is now read-only.

Commit

Permalink
Migrate to YAML configuration (#214)
Browse files Browse the repository at this point in the history
* [Sugarcane-0022] Add YAML comments

* Add nacho.yml

* Move configuration options to new yml file

* Add migration

* Update NachoConfig.java

* Fix some errors

* More categories

* More tests & checks

* Comments

* Fix error

* Update README.md

* Fix conflicts

* Move some options to world config

* Change configuration version
  • Loading branch information
Elier authored Nov 3, 2021
1 parent 6d58604 commit ebf0841
Show file tree
Hide file tree
Showing 36 changed files with 743 additions and 106 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<PacketListener> packetListeners = Sets.newConcurrentHashSet();
private final Set<MovementListener> 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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SocketChannel>
{
Expand All @@ -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) {}
Expand Down
Loading

0 comments on commit ebf0841

Please sign in to comment.