forked from afspiegeling/NitoriBot
config creation
This commit is contained in:
+4
-1
@@ -8,4 +8,7 @@ build
|
||||
.kotlin
|
||||
|
||||
# Ignore the bin folder vscode keeps creating
|
||||
bin
|
||||
bin
|
||||
|
||||
# Ignore the config
|
||||
config.yaml
|
||||
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"java.configuration.updateBuildConfiguration": "automatic",
|
||||
"java.compile.nullAnalysis.mode": "disabled"
|
||||
}
|
||||
@@ -31,6 +31,7 @@ kotlin {
|
||||
implementation("org.tinylog:tinylog-api-kotlin:2.7.0")
|
||||
implementation("org.tinylog:tinylog-impl:2.7.0")
|
||||
implementation("org.slf4j:slf4j-api:2.0.12")
|
||||
implementation("org.yaml:snakeyaml:2.2")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package land.chipmunk.parker2991.fnfboyfriendbot;
|
||||
import org.geysermc.mcprotocollib.protocol.MinecraftProtocol;
|
||||
import org.geysermc.mcprotocollib.network.event.session.DisconnectedEvent;
|
||||
import org.geysermc.mcprotocollib.network.event.session.SessionAdapter;
|
||||
import org.geysermc.mcprotocollib.network.session.ClientNetworkSession;
|
||||
import org.geysermc.mcprotocollib.network.factory.ClientNetworkSessionFactory;
|
||||
|
||||
public class Bot extends SessionAdapter {
|
||||
public ClientNetworkSession session;
|
||||
|
||||
public String host = "opt.chipmunk.land";
|
||||
|
||||
public int port = 25565;
|
||||
|
||||
public String username = "meow";
|
||||
|
||||
public final Object obj = new Object();
|
||||
|
||||
public void Bot () {
|
||||
System.out.println("meow");
|
||||
final MinecraftProtocol protocol = new MinecraftProtocol(this.username);
|
||||
|
||||
session = ClientNetworkSessionFactory.factory()
|
||||
.setAddress(
|
||||
this.host,
|
||||
this.port
|
||||
)
|
||||
.setProtocol(protocol)
|
||||
.create();
|
||||
session.addListener(this);
|
||||
session.connect();
|
||||
try {
|
||||
synchronized(obj) {
|
||||
obj.wait();
|
||||
};
|
||||
} catch (final InterruptedException ignored) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
public void connect () {
|
||||
try {
|
||||
synchronized(obj) {
|
||||
obj.wait();
|
||||
};
|
||||
} catch (final InterruptedException ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnect (DisconnectedEvent event) {
|
||||
System.out.println(event);
|
||||
}
|
||||
}
|
||||
@@ -1,56 +1,61 @@
|
||||
// Thanks Blackilykat and OptmisticDev for helping me with the client creation
|
||||
// Thanks Blackilykat and OptmisticDev and PthePro777 helping me with the client creation
|
||||
package land.chipmunk.parker2991.fnfboyfriendbot;
|
||||
|
||||
import org.geysermc.mcprotocollib.protocol.MinecraftProtocol;
|
||||
import org.geysermc.mcprotocollib.network.event.session.DisconnectedEvent;
|
||||
import org.geysermc.mcprotocollib.network.event.session.SessionAdapter;
|
||||
import org.geysermc.mcprotocollib.network.session.ClientNetworkSession;
|
||||
import org.geysermc.mcprotocollib.network.factory.ClientNetworkSessionFactory;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
public class Main extends SessionAdapter{
|
||||
public ClientNetworkSession session;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
// throws URISyntaxException
|
||||
public class Main {
|
||||
|
||||
public String host = "opt.chipmunk.land";
|
||||
public Object config;
|
||||
|
||||
public int port = 25565;
|
||||
public static final List<Bot> Bots = new ArrayList<>();
|
||||
|
||||
public String username = "meow";
|
||||
|
||||
public final Object obj = new Object();
|
||||
public void loadConfig() {
|
||||
// Blackilykat helped me with the file coping and PthePro777 helped me with reading the file
|
||||
try {
|
||||
final Yaml yaml = new Yaml();
|
||||
final Path path = Path.of("config.yaml");
|
||||
|
||||
if (!Files.exists(path)) {
|
||||
System.out.println("config not found making config now");
|
||||
|
||||
InputStream defaultConfig = Main.class.getClassLoader().getResourceAsStream("default_config.yaml");//.getResource("default_config.yaml");//.getResource("default_config.yaml");
|
||||
Files.copy(defaultConfig, Paths.get("config.yaml"));
|
||||
}
|
||||
|
||||
InputStream configFile = Files.newInputStream(path);
|
||||
Object config = yaml.load(configFile);
|
||||
this.config = config;
|
||||
} catch (final IOException error) {}
|
||||
};
|
||||
|
||||
public void main(String[] args) {
|
||||
System.out.println("meow");
|
||||
final MinecraftProtocol protocol = new MinecraftProtocol(this.username);
|
||||
this.loadConfig();
|
||||
config = this.config;
|
||||
|
||||
session = ClientNetworkSessionFactory.factory()
|
||||
.setAddress(
|
||||
this.host,
|
||||
this.port
|
||||
)
|
||||
.setProtocol(protocol)
|
||||
.create();
|
||||
session.addListener(this);
|
||||
session.connect();
|
||||
try {
|
||||
synchronized(obj) {
|
||||
obj.wait();
|
||||
};
|
||||
} catch (final InterruptedException ignored) {
|
||||
Bot
|
||||
Main.Bots bots = config.bots;
|
||||
//bots[] = config.bots;
|
||||
|
||||
}
|
||||
//config = this.config;
|
||||
|
||||
//bots = config.bots;
|
||||
|
||||
for (this.config.bots Bots: options) {
|
||||
System.out.println();
|
||||
};
|
||||
|
||||
//Bot bot = new Bot(config);
|
||||
//System.out.println(this.config);
|
||||
};
|
||||
|
||||
public void connect () {
|
||||
try {
|
||||
synchronized(obj) {
|
||||
obj.wait();
|
||||
};
|
||||
} catch (final InterruptedException ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnect (DisconnectedEvent event) {
|
||||
System.out.println(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
bots:
|
||||
- host: "localhost"
|
||||
port: 25565
|
||||
username: "meow"
|
||||
Reference in New Issue
Block a user