Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
now it looks good
Browse files Browse the repository at this point in the history
  • Loading branch information
MelonHell committed Jan 30, 2024
1 parent bef47b8 commit 2f49b70
Show file tree
Hide file tree
Showing 219 changed files with 1,766 additions and 1,744 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ allprojects {
tasks.withType<Test> {
useJUnitPlatform()

maxHeapSize = "2048m"

// Viewable packets make tracking harder. Could be re-enabled later.
jvmArgs("-Dminestom.viewable-packet=false")
jvmArgs("-Dminestom.inside-test=true")
Expand Down
30 changes: 15 additions & 15 deletions demo/src/main/java/net/minestom/demo/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import net.minestom.demo.block.TestBlockHandler;
import net.minestom.demo.block.placement.DripstonePlacementRule;
import net.minestom.demo.commands.*;
import net.minestom.server.MinecraftServer;
import net.minestom.server.ServerProcess;
import net.minestom.server.ServerSettings;
import net.minestom.server.command.CommandManager;
import net.minestom.server.event.server.ServerListPingEvent;
import net.minestom.server.extras.lan.OpenToLAN;
Expand All @@ -25,23 +26,22 @@ public class Main {
public static void main(String[] args) {
System.setProperty("minestom.experiment.pose-updates", "true");

MinecraftServer minecraftServer = new MinecraftServer();
ServerSettings serverSettings = ServerSettings.builder().compressionThreshold(0).build();

minecraftServer.setCompressionThreshold(0);
ServerProcess serverProcess = ServerProcess.of(serverSettings);

minecraftServer.init();

BlockManager blockManager = minecraftServer.process().getBlockManager();
BlockManager blockManager = serverProcess.getBlockManager();
blockManager.registerBlockPlacementRule(new DripstonePlacementRule());
blockManager.registerHandler(TestBlockHandler.INSTANCE.getNamespaceId(), () -> TestBlockHandler.INSTANCE);

CommandManager commandManager = minecraftServer.process().getCommandManager();
CommandManager commandManager = serverProcess.getCommandManager();
commandManager.register(new TestCommand());
commandManager.register(new EntitySelectorCommand());
commandManager.register(new HealthCommand());
commandManager.register(new LegacyCommand());
commandManager.register(new DimensionCommand(minecraftServer));
commandManager.register(new ShutdownCommand(minecraftServer));
commandManager.register(new DimensionCommand(serverProcess));
commandManager.register(new ShutdownCommand(serverProcess));
commandManager.register(new TeleportCommand());
commandManager.register(new PlayersCommand());
commandManager.register(new FindCommand());
Expand All @@ -63,15 +63,15 @@ public static void main(String[] args) {
commandManager.register(new NotificationCommand());
commandManager.register(new TestCommand2());
commandManager.register(new ConfigCommand());
commandManager.register(new SidebarCommand(minecraftServer));
commandManager.register(new SidebarCommand(serverProcess));

commandManager.setUnknownCommandCallback((sender, command) -> sender.sendMessage(Component.text("Unknown command", NamedTextColor.RED)));

minecraftServer.process().getBenchmarkManager().enable(Duration.of(10, TimeUnit.SECOND));
serverProcess.getBenchmarkManager().enable(Duration.of(10, TimeUnit.SECOND));

minecraftServer.process().getSchedulerManager().buildShutdownTask(() -> System.out.println("Good night"));
serverProcess.getSchedulerManager().buildShutdownTask(() -> System.out.println("Good night"));

minecraftServer.process().getGlobalEventHandler().addListener(ServerListPingEvent.class, event -> {
serverProcess.getGlobalEventHandler().addListener(ServerListPingEvent.class, event -> {
ResponseData responseData = event.getResponseData();
responseData.addEntry(NamedAndIdentified.named("The first line is separated from the others"));
responseData.addEntry(NamedAndIdentified.named("Could be a name, or a message"));
Expand Down Expand Up @@ -105,17 +105,17 @@ public static void main(String[] args) {
//responseData.setPlayersHidden(true);
});

new PlayerInit(minecraftServer).init();
new PlayerInit(serverProcess).init();

// VelocityProxy.enable("abcdef");
//BungeeCordProxy.enable();

//MojangAuth.init();

// useful for testing - we don't need to worry about event calls so just set this to a long time
new OpenToLAN(minecraftServer).open(new OpenToLANConfig().eventCallDelay(Duration.of(1, TimeUnit.DAY)));
new OpenToLAN(serverProcess).open(new OpenToLANConfig().eventCallDelay(Duration.of(1, TimeUnit.DAY)));

minecraftServer.start("0.0.0.0", 25565);
serverProcess.start("0.0.0.0", 25565);
// minecraftServer.start(java.net.UnixDomainSocketAddress.of("minestom-demo.sock"));
//Runtime.getRuntime().addShutdownHook(new Thread(MinecraftServer::stopCleanly));
}
Expand Down
17 changes: 7 additions & 10 deletions demo/src/main/java/net/minestom/demo/PlayerInit.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.minestom.demo;

import net.kyori.adventure.text.Component;
import net.minestom.server.MinecraftServer;
import net.minestom.server.ServerProcess;
import net.minestom.server.advancements.FrameType;
import net.minestom.server.advancements.notifications.Notification;
Expand Down Expand Up @@ -47,12 +46,10 @@

public class PlayerInit {

private final MinecraftServer minecraftServer;
private final ServerProcess serverProcess;

public PlayerInit(MinecraftServer minecraftServer) {
this.minecraftServer = minecraftServer;
this.serverProcess = minecraftServer.process();
public PlayerInit(ServerProcess serverProcess) {
this.serverProcess = serverProcess;
InstanceManager instanceManager = serverProcess.getInstanceManager();

InstanceContainer instanceContainer = instanceManager.createInstanceContainer(DimensionType.OVERWORLD);
Expand All @@ -73,10 +70,10 @@ public PlayerInit(MinecraftServer minecraftServer) {
// System.out.println("load end");
// });

inventory = new Inventory(minecraftServer, InventoryType.CHEST_1_ROW, Component.text("Test inventory"));
inventory = new Inventory(serverProcess, InventoryType.CHEST_1_ROW, Component.text("Test inventory"));
inventory.setItemStack(3, ItemStack.of(Material.DIAMOND, 34));

DEMO_NODE = EventNode.all(minecraftServer, "demo")
DEMO_NODE = EventNode.all(serverProcess, "demo")
.addListener(EntityAttackEvent.class, event -> {
final Entity source = event.getEntity();
final Entity entity = event.getTarget();
Expand Down Expand Up @@ -106,13 +103,13 @@ public PlayerInit(MinecraftServer minecraftServer) {
ItemStack droppedItem = event.getItemStack();

Pos playerPos = player.getPosition();
ItemEntity itemEntity = new ItemEntity(minecraftServer, droppedItem);
ItemEntity itemEntity = new ItemEntity(serverProcess, droppedItem);
itemEntity.setPickupDelay(Duration.of(500, TimeUnit.MILLISECOND));
itemEntity.setInstance(player.getInstance(), playerPos.withY(y -> y + 1.5));
Vec velocity = playerPos.direction().mul(6);
itemEntity.setVelocity(velocity);

FakePlayer.initPlayer(minecraftServer, UUID.randomUUID(), "fake123", fp -> {
FakePlayer.initPlayer(serverProcess, UUID.randomUUID(), "fake123", fp -> {
System.out.println("fp = " + fp);
});
})
Expand Down Expand Up @@ -225,6 +222,6 @@ public void init() {
.append(Component.text("ACQ TIME: " + MathUtils.round(tickMonitor.getAcquisitionTime(), 2) + "ms"));
final Component footer = benchmarkManager.getCpuMonitoringMessage();
serverProcess.getAudiences().players().sendPlayerListHeaderAndFooter(header, footer);
}).repeat(10, TimeUnit.SERVER_TICK); //.schedule();
}).repeat(10, TimeUnit.getServerTick(serverProcess.getMinecraftServer())); //.schedule();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.minestom.demo.commands;

import net.minestom.server.MinecraftServer;
import net.minestom.server.ServerProcess;
import net.minestom.server.command.builder.Command;
import net.minestom.server.command.builder.condition.Conditions;
import net.minestom.server.entity.Player;
Expand All @@ -10,14 +10,14 @@

public class DimensionCommand extends Command {

public DimensionCommand(MinecraftServer minecraftServer) {
public DimensionCommand(ServerProcess serverProcess) {
super("dimensiontest");
setCondition(Conditions::playerOnly);

addSyntax((sender, context) -> {
final Player player = (Player) sender;
final Instance instance = player.getInstance();
final var instances = minecraftServer.process().getInstanceManager().getInstances().stream().filter(instance1 -> !instance1.equals(instance)).toList();
final var instances = serverProcess.getInstanceManager().getInstances().stream().filter(instance1 -> !instance1.equals(instance)).toList();
if (instances.isEmpty()) {
player.sendMessage("No instance available");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import net.minestom.server.utils.time.TimeUnit;
import org.jetbrains.annotations.NotNull;

import java.time.temporal.TemporalUnit;

public class DisplayCommand extends Command {

public DisplayCommand() {
Expand All @@ -38,7 +40,7 @@ public void spawnItem(@NotNull CommandSender sender, @NotNull CommandContext con
if (!(sender instanceof Player player))
return;

var entity = new Entity(sender.getMinecraftServer(), EntityType.ITEM_DISPLAY);
var entity = new Entity(sender.getServerProcess(), EntityType.ITEM_DISPLAY);
var meta = (ItemDisplayMeta) entity.getEntityMeta();
meta.setTransformationInterpolationDuration(20);
meta.setItemStack(ItemStack.of(Material.STICK));
Expand All @@ -53,7 +55,7 @@ public void spawnBlock(@NotNull CommandSender sender, @NotNull CommandContext co
if (!(sender instanceof Player player))
return;

var entity = new Entity(sender.getMinecraftServer(), EntityType.BLOCK_DISPLAY);
var entity = new Entity(sender.getServerProcess(), EntityType.BLOCK_DISPLAY);
var meta = (BlockDisplayMeta) entity.getEntityMeta();
meta.setTransformationInterpolationDuration(20);
meta.setBlockState(Block.ORANGE_CANDLE_CAKE.stateId());
Expand All @@ -68,7 +70,7 @@ public void spawnText(@NotNull CommandSender sender, @NotNull CommandContext con
if (!(sender instanceof Player player))
return;

var entity = new Entity(sender.getMinecraftServer(), EntityType.TEXT_DISPLAY);
var entity = new Entity(sender.getServerProcess(), EntityType.TEXT_DISPLAY);
var meta = (TextDisplayMeta) entity.getEntityMeta();
meta.setTransformationInterpolationDuration(20);
meta.setBillboardRenderConstraints(AbstractDisplayMeta.BillboardConstraints.CENTER);
Expand All @@ -83,7 +85,8 @@ public void spawnText(@NotNull CommandSender sender, @NotNull CommandContext con
private void startSmoothFollow(@NotNull Entity entity, @NotNull Player player) {
// entity.setCustomName(Component.text("MY CUSTOM NAME"));
// entity.setCustomNameVisible(true);
entity.getMinecraftServer().process().getSchedulerManager().buildTask(() -> {
TemporalUnit serverTick = TimeUnit.getServerTick(entity.getServerProcess().getMinecraftServer());
entity.getServerProcess().getSchedulerManager().buildTask(() -> {
var meta = (AbstractDisplayMeta) entity.getEntityMeta();
meta.setNotifyAboutChanges(false);
meta.setTransformationInterpolationStartDelta(1);
Expand All @@ -93,6 +96,6 @@ private void startSmoothFollow(@NotNull Entity entity, @NotNull Player player) {
// meta.setScale(new Vec(5, 5, 5));
meta.setTranslation(player.getPosition().sub(entity.getPosition()));
meta.setNotifyAboutChanges(true);
}).delay(20, TimeUnit.SERVER_TICK).repeat(20, TimeUnit.SERVER_TICK).schedule();
}).delay(20, serverTick).repeat(20, serverTick).schedule();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void onHorseCommand(CommandSender sender, CommandContext context) {
boolean baby = context.get("baby");
HorseMeta.Marking marking = context.get("marking");
HorseMeta.Color color = context.get("color");
var horse = new EntityCreature(sender.getMinecraftServer(), EntityType.HORSE);
var horse = new EntityCreature(sender.getServerProcess(), EntityType.HORSE);
var meta = (HorseMeta) horse.getEntityMeta();
meta.setBaby(baby);
meta.setVariant(new HorseMeta.Variant(marking, color));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public PlayersCommand() {
}

private void usage(CommandSender sender, CommandContext context) {
final var players = List.copyOf(sender.getMinecraftServer().process().getConnectionManager().getOnlinePlayers());
final var players = List.copyOf(sender.getServerProcess().getConnectionManager().getOnlinePlayers());
final int playerCount = players.size();
sender.sendMessage(Component.text("Total players: " + playerCount));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public SaveCommand() {
}

private void execute(@NotNull CommandSender commandSender, @NotNull CommandContext commandContext) {
for(var instance : commandSender.getMinecraftServer().process().getInstanceManager().getInstances()) {
for(var instance : commandSender.getServerProcess().getInstanceManager().getInstances()) {
CompletableFuture<Void> instanceSave = instance.saveInstance().thenCompose(v -> instance.saveChunksToStorage());
try {
instanceSave.get();
} catch (InterruptedException | ExecutionException e) {
commandSender.getMinecraftServer().process().getExceptionManager().handleException(e);
commandSender.getServerProcess().getExceptionManager().handleException(e);
}
}
commandSender.sendMessage("Saving done!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ private void onShootCommand(CommandSender sender, CommandContext context) {
EntityProjectile projectile;
switch (mode) {
case "default":
projectile = new EntityProjectile(player.getMinecraftServer(), player, EntityType.ARROW);
projectile = new EntityProjectile(player.getServerProcess(), player, EntityType.ARROW);
break;
case "spectral":
projectile = new EntityProjectile(player.getMinecraftServer(), player, EntityType.SPECTRAL_ARROW);
projectile = new EntityProjectile(player.getServerProcess(), player, EntityType.SPECTRAL_ARROW);
break;
case "colored":
projectile = new EntityProjectile(player.getMinecraftServer(), player, EntityType.ARROW);
projectile = new EntityProjectile(player.getServerProcess(), player, EntityType.ARROW);
var meta = (ArrowMeta) projectile.getEntityMeta();
meta.setColor(ThreadLocalRandom.current().nextInt());
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.minestom.demo.commands;

import net.minestom.server.MinecraftServer;
import net.minestom.server.ServerProcess;
import net.minestom.server.command.CommandSender;
import net.minestom.server.command.builder.Command;
import net.minestom.server.command.builder.CommandContext;
Expand All @@ -11,15 +11,15 @@
*/
public class ShutdownCommand extends Command {

private final MinecraftServer minecraftServer;
private final ServerProcess serverProcess;

public ShutdownCommand(MinecraftServer minecraftServer) {
public ShutdownCommand(ServerProcess serverProcess) {
super("shutdown");
this.minecraftServer = minecraftServer;
this.serverProcess = serverProcess;
addSyntax(this::execute);
}

private void execute(@NotNull CommandSender commandSender, @NotNull CommandContext commandContext) {
minecraftServer.stopCleanly();
serverProcess.stop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.minestom.server.MinecraftServer;
import net.minestom.server.ServerProcess;
import net.minestom.server.command.CommandSender;
import net.minestom.server.command.builder.Command;
import net.minestom.server.command.builder.CommandContext;
Expand All @@ -18,10 +18,10 @@ public class SidebarCommand extends Command {
private final Sidebar sidebar;
private int currentLine = 0;

public SidebarCommand(MinecraftServer minecraftServer) {
public SidebarCommand(ServerProcess serverProcess) {
super("sidebar");

sidebar = new Sidebar(minecraftServer, Component.text("DEMO").decorate(TextDecoration.BOLD));
sidebar = new Sidebar(serverProcess, Component.text("DEMO").decorate(TextDecoration.BOLD));

addLine("BLANK ", Sidebar.NumberFormat.blank());
addLine("STYLE ", Sidebar.NumberFormat.styled(Component.empty().decorate(TextDecoration.STRIKETHROUGH).color(NamedTextColor.GRAY)));
Expand Down
10 changes: 5 additions & 5 deletions demo/src/main/java/net/minestom/demo/commands/SummonCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.minestom.demo.commands;

import net.minestom.server.MinecraftServer;
import net.minestom.server.ServerProcess;
import net.minestom.server.command.CommandSender;
import net.minestom.server.command.builder.Command;
import net.minestom.server.command.builder.CommandContext;
Expand Down Expand Up @@ -38,7 +38,7 @@ public SummonCommand() {
}

private void execute(@NotNull CommandSender commandSender, @NotNull CommandContext commandContext) {
final Entity entity = commandContext.get(entityClass).instantiate(commandSender.getMinecraftServer(), commandContext.get(this.entity));
final Entity entity = commandContext.get(entityClass).instantiate(commandSender.getServerProcess(), commandContext.get(this.entity));
//noinspection ConstantConditions - One couldn't possibly execute a command without being in an instance
entity.setInstance(((Player) commandSender).getInstance(), commandContext.get(pos).fromSender(commandSender));
}
Expand All @@ -54,12 +54,12 @@ enum EntityClass {
this.factory = factory;
}

public Entity instantiate(MinecraftServer minecraftServer, EntityType type) {
return factory.newInstance(minecraftServer, type);
public Entity instantiate(ServerProcess serverProcess, EntityType type) {
return factory.newInstance(serverProcess, type);
}
}

interface EntityFactory {
Entity newInstance(MinecraftServer minecraftServer, EntityType type);
Entity newInstance(ServerProcess serverProcess, EntityType type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public TeleportCommand() {

private void onPlayerTeleport(CommandSender sender, CommandContext context) {
final String playerName = context.get("player");
Player pl = sender.getMinecraftServer().process().getConnectionManager().getOnlinePlayerByUsername(playerName);
Player pl = sender.getServerProcess().getConnectionManager().getOnlinePlayerByUsername(playerName);
if (sender instanceof Player player) {
player.teleport(pl.getPosition());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.minestom.demo.entity;

import net.minestom.server.MinecraftServer;
import net.minestom.server.ServerProcess;
import net.minestom.server.attribute.Attribute;
import net.minestom.server.entity.EntityCreature;
import net.minestom.server.entity.EntityType;
Expand All @@ -10,8 +10,8 @@

public class ChickenCreature extends EntityCreature {

public ChickenCreature(MinecraftServer minecraftServer) {
super(minecraftServer, EntityType.CHICKEN);
public ChickenCreature(ServerProcess serverProcess) {
super(serverProcess, EntityType.CHICKEN);

addAIGroup(
List.of(
Expand Down
Loading

0 comments on commit 2f49b70

Please sign in to comment.