Add online_mode and velocity_secret config options
Some checks failed
Build JStom / build (push) Failing after 53s

This commit is contained in:
2026-01-26 01:26:02 +00:00
parent d06d9bf9d9
commit e06b356531
5 changed files with 98 additions and 0 deletions

View File

@@ -2,3 +2,5 @@
host: "0.0.0.0"
port: 25565
motd: "A JStom Server"
online_mode: true
velocity_secret: ""

52
scripts/elytra_boost.js Normal file
View File

@@ -0,0 +1,52 @@
const Material = Java.type('net.minestom.server.item.Material');
const Sound = Java.type('net.kyori.adventure.sound.Sound');
const SoundEvent = Java.type('net.minestom.server.sound.SoundEvent');
const Entity = Java.type('net.minestom.server.entity.Entity');
const EntityType = Java.type('net.minestom.server.entity.EntityType');
const Duration = Java.type('java.time.Duration');
server.log("Vanilla Elytra Boost loaded.");
server.on('net.minestom.server.event.player.PlayerUseItemEvent', (event) => {
const player = event.getPlayer();
const item = event.getItemStack();
// 1. Validate Condition
if (item.material().name() !== "minecraft:firework_rocket") return;
if (!player.isFlyingWithElytra()) return;
// 2. Consume Item (if not creative)
if (player.getGameMode().name() !== "CREATIVE") {
player.setItemInHand(event.getHand(), item.withAmount(item.amount() - 1));
}
// 3. Spawn Firework Rocket
// The entity itself handles the boosting physics in Minestom/Client
const rocket = new Entity(EntityType.fromKey("minecraft:firework_rocket"));
const meta = rocket.getEntityMeta();
meta.setFireworkInfo(item);
meta.setShooter(player);
// Spawn at player position
rocket.setInstance(player.getInstance(), player.getPosition());
// Set rocket velocity to fly in look direction
const direction = player.getPosition().direction();
rocket.setVelocity(direction.mul(1.5)); // Adjust rocket speed if needed
// Cleanup: Remove rocket after lifetime (e.g., 1.5s for duration 3)
// Vanilla duration calculation is roughly (FlightDuration + 1) * 10 + random ticks
// 1.5s is a safe average for Duration 3
rocket.scheduleRemove(Duration.ofMillis(1500));
// 4. Play Sound
const launchSound = Sound.sound(
SoundEvent.fromKey("minecraft:entity.firework_rocket.launch"),
Sound.Source.PLAYER,
3.0,
1.0
);
player.getViewers().forEach(v => v.playSound(launchSound, player.getPosition()));
player.playSound(launchSound);
});

25
scripts/elytra_spawn.js Normal file
View File

@@ -0,0 +1,25 @@
const ItemStack = Java.type('net.minestom.server.item.ItemStack');
const Material = Java.type('net.minestom.server.item.Material');
const EquipmentSlot = Java.type('net.minestom.server.entity.EquipmentSlot');
const DataComponents = Java.type('net.minestom.server.component.DataComponents');
const FireworkList = Java.type('net.minestom.server.item.component.FireworkList');
server.log("Elytra script loaded!");
server.on('net.minestom.server.event.player.PlayerSpawnEvent', (event) => {
const player = event.getPlayer();
// Create items using fromKey (safer than static field access)
const elytra = ItemStack.of(Material.fromKey("minecraft:elytra"));
// Create fireworks with flight duration 3
var fireworks = ItemStack.of(Material.fromKey("minecraft:firework_rocket"))
.withAmount(64)
.with(DataComponents.FIREWORKS, FireworkList.EMPTY.withFlightDuration(3));
// Equip items
player.setEquipment(EquipmentSlot.CHESTPLATE, elytra);
player.setEquipment(EquipmentSlot.OFF_HAND, fireworks);
player.sendMessage("You have been equipped with an Elytra and Fireworks (Flight Duration 3)!");
});

View File

@@ -12,6 +12,8 @@ public class Config {
public static int PORT = 25565;
public static String MOTD = "A JStom Server";
public static String HOST = "0.0.0.0";
public static boolean ONLINE_MODE = true;
public static String VELOCITY_SECRET = "";
private static final String CONFIG_FILE = "config.yml";
@@ -28,6 +30,8 @@ public class Config {
if (data != null) {
if (data.containsKey("port")) PORT = (int) data.get("port");
if (data.containsKey("motd")) MOTD = (String) data.get("motd");
if (data.containsKey("online_mode")) ONLINE_MODE = (boolean) data.get("online_mode");
if (data.containsKey("velocity_secret")) VELOCITY_SECRET = (String) data.get("velocity_secret");
if (data.containsKey("host")) {
String rawHost = (String) data.get("host");
if (rawHost.contains(":")) {
@@ -48,6 +52,8 @@ public class Config {
writer.write("host: \"0.0.0.0\"\n");
writer.write("port: 25565\n");
writer.write("motd: \"A JStom Server\"\n");
writer.write("online_mode: true\n");
writer.write("velocity_secret: \"\"\n");
} catch (IOException e) {
e.printStackTrace();
}

View File

@@ -7,6 +7,8 @@ import net.minestom.server.entity.Player;
import net.minestom.server.event.GlobalEventHandler;
import net.minestom.server.event.player.AsyncPlayerConfigurationEvent;
import net.minestom.server.event.server.ServerListPingEvent;
import net.minestom.server.extras.MojangAuth;
import net.minestom.server.extras.velocity.VelocityProxy;
import net.minestom.server.instance.InstanceContainer;
import net.minestom.server.instance.InstanceManager;
import net.minestom.server.instance.LightingChunk;
@@ -25,6 +27,17 @@ public class Main {
// Initialize server
MinecraftServer minecraftServer = MinecraftServer.init();
// Auth
if (!Config.VELOCITY_SECRET.isEmpty()) {
VelocityProxy.enable(Config.VELOCITY_SECRET);
System.out.println("Velocity forwarding enabled.");
} else if (Config.ONLINE_MODE) {
MojangAuth.init();
System.out.println("Online mode enabled.");
} else {
System.out.println("Running in offline mode.");
}
InstanceManager instanceManager = MinecraftServer.getInstanceManager();
// Create the instance
InstanceContainer instanceContainer = instanceManager.createInstanceContainer();