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

Commit

Permalink
little changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MelonHell committed Jan 30, 2024
1 parent 2f49b70 commit 5ad4b14
Show file tree
Hide file tree
Showing 79 changed files with 356 additions and 363 deletions.
4 changes: 2 additions & 2 deletions demo/src/main/java/net/minestom/demo/PlayerInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public PlayerInit(ServerProcess serverProcess) {
this.serverProcess = serverProcess;
InstanceManager instanceManager = serverProcess.getInstanceManager();

InstanceContainer instanceContainer = instanceManager.createInstanceContainer(DimensionType.OVERWORLD);
InstanceContainer instanceContainer = instanceManager.createInstanceContainer(serverProcess, DimensionType.OVERWORLD);
instanceContainer.setGenerator(unit -> unit.modifier().fillHeight(0, 40, Block.STONE));
instanceContainer.setChunkSupplier(LightingChunk::new);

Expand Down Expand Up @@ -222,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.getServerTick(serverProcess.getMinecraftServer())); //.schedule();
}).repeat(10, TimeUnit.getServerTick(serverProcess.getServerSetting())); //.schedule();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ 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);
TemporalUnit serverTick = TimeUnit.getServerTick(entity.getServerProcess().getMinecraftServer());
TemporalUnit serverTick = TimeUnit.getServerTick(entity.getServerProcess().getServerSetting());
entity.getServerProcess().getSchedulerManager().buildTask(() -> {
var meta = (AbstractDisplayMeta) entity.getEntityMeta();
meta.setNotifyAboutChanges(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private void execute(@NotNull CommandSender commandSender, @NotNull CommandConte
try {
instanceSave.get();
} catch (InterruptedException | ExecutionException e) {
commandSender.getServerProcess().getExceptionManager().handleException(e);
commandSender.getServerProcess().getExceptionHandler().handleException(e);
}
}
commandSender.sendMessage("Saving done!");
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/minestom/server/ServerProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.minestom.server.adventure.bossbar.BossBarManager;
import net.minestom.server.command.CommandManager;
import net.minestom.server.event.GlobalEventHandler;
import net.minestom.server.exception.ExceptionManager;
import net.minestom.server.exception.ExceptionHandler;
import net.minestom.server.extras.MojangAuth;
import net.minestom.server.gamedata.tags.TagManager;
import net.minestom.server.instance.Chunk;
Expand Down Expand Up @@ -39,7 +39,7 @@ static ServerProcess of(ServerSettings serverSettings) {
return new ServerProcessImpl(serverSettings);
}

ServerSettings getMinecraftServer();
ServerSettings getServerSetting();

/**
* Handles incoming connections/players.
Expand Down Expand Up @@ -114,7 +114,7 @@ static ServerProcess of(ServerSettings serverSettings) {
/**
* Handles all thrown exceptions from the server.
*/
@NotNull ExceptionManager getExceptionManager();
@NotNull ExceptionHandler getExceptionHandler();

/**
* Handles incoming packets.
Expand Down
39 changes: 23 additions & 16 deletions src/main/java/net/minestom/server/ServerProcessImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import net.minestom.server.entity.Entity;
import net.minestom.server.event.GlobalEventHandler;
import net.minestom.server.event.server.ServerTickMonitorEvent;
import net.minestom.server.exception.ExceptionManager;
import net.minestom.server.exception.ExceptionHandler;
import net.minestom.server.exception.ExceptionHandlerImpl;
import net.minestom.server.extras.MojangAuth;
import net.minestom.server.gamedata.tags.TagManager;
import net.minestom.server.instance.Chunk;
Expand All @@ -34,21 +35,23 @@
import net.minestom.server.world.DimensionTypeManager;
import net.minestom.server.world.biomes.BiomeManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

final class ServerProcessImpl implements ServerProcess {
private static final Logger LOGGER = LoggerFactory.getLogger(ServerProcessImpl.class);
private static final Boolean SHUTDOWN_ON_SIGNAL = PropertyUtils.getBoolean("minestom.shutdown-on-signal", true);

private final ExceptionManager exceptionManager;
private final ExceptionHandler exceptionHandler;
private final ConnectionManager connectionManager;
private final PacketListenerManager packetListenerManager;
private final PacketProcessor packetProcessor;
Expand Down Expand Up @@ -77,34 +80,38 @@ final class ServerProcessImpl implements ServerProcess {
private final MojangAuth mojangAuth;

public ServerProcessImpl(ServerSettings serverSettings) {
this(serverSettings, null);
}

public ServerProcessImpl(ServerSettings serverSettings, @Nullable ExceptionHandler exceptionHandler) {
this.serverSettings = serverSettings;
this.exceptionManager = new ExceptionManager(this);
this.packetListenerManager = new PacketListenerManager(this);
this.exceptionHandler = Objects.requireNonNullElseGet(exceptionHandler, () -> new ExceptionHandlerImpl(this));
this.globalEventHandler = new GlobalEventHandler(exceptionHandler);
this.packetListenerManager = new PacketListenerManager(globalEventHandler, exceptionHandler);
this.packetProcessor = new PacketProcessor(packetListenerManager);
this.instanceManager = new InstanceManager(this);
this.dispatcher = ThreadDispatcher.singleThread(exceptionHandler);
this.instanceManager = new InstanceManager(dispatcher, globalEventHandler);
this.blockManager = new BlockManager();
this.commandManager = new CommandManager(this);
this.recipeManager = new RecipeManager();
this.teamManager = new TeamManager(this);
this.globalEventHandler = new GlobalEventHandler(this);
this.schedulerManager = new SchedulerManager();
this.benchmarkManager = new BenchmarkManager(this);
this.benchmarkManager = new BenchmarkManager(exceptionHandler);
this.dimensionTypeManager = new DimensionTypeManager();
this.biomeManager = new BiomeManager();
this.advancementManager = new AdvancementManager(this);
this.bossBarManager = new BossBarManager(this);
this.tagManager = new TagManager();
this.connectionManager = new ConnectionManager(this, tagManager);
this.connectionManager = new ConnectionManager(this, serverSettings, tagManager);
this.server = new Server(this, packetProcessor);
this.mojangAuth = new MojangAuth(this);
this.audiences = new Audiences(this);
this.mojangAuth = new MojangAuth(this, exceptionHandler);
this.audiences = new Audiences(this, connectionManager, commandManager);

this.dispatcher = ThreadDispatcher.singleThread(this);
this.ticker = new TickerImpl();
}

@Override
public ServerSettings getMinecraftServer() {
public ServerSettings getServerSetting() {
return serverSettings;
}

Expand Down Expand Up @@ -179,8 +186,8 @@ public ServerSettings getMinecraftServer() {
}

@Override
public @NotNull ExceptionManager getExceptionManager() {
return exceptionManager;
public @NotNull ExceptionHandler getExceptionHandler() {
return exceptionHandler;
}

@Override
Expand Down Expand Up @@ -220,7 +227,7 @@ public void start(@NotNull SocketAddress socketAddress) {
try {
server.init(socketAddress);
} catch (IOException e) {
exceptionManager.handleException(e);
exceptionHandler.handleException(e);
throw new RuntimeException(e);
}

Expand Down Expand Up @@ -311,7 +318,7 @@ private void serverTick(long tickStart) {
try {
instance.tick(tickStart);
} catch (Exception e) {
getExceptionManager().handleException(e);
getExceptionHandler().handleException(e);
}
}
// Tick all chunks (and entities inside)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/minestom/server/Viewable.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ default boolean isViewer(@NotNull Player player) {
*/
default void sendPacketToViewers(@NotNull SendablePacket packet) {
if (packet instanceof ServerPacket serverPacket) {
PacketUtils.sendGroupedPacket(getServerProcess(), getViewers(), serverPacket);
PacketUtils.sendGroupedPacket(getServerProcess().getServerSetting(), getViewers(), serverPacket);
} else {
getViewers().forEach(player -> player.sendPacket(packet));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.Keyed;
import net.minestom.server.ServerProcess;
import net.minestom.server.command.CommandManager;
import net.minestom.server.entity.Player;
import net.minestom.server.network.ConnectionManager;
import org.jetbrains.annotations.NotNull;
Expand All @@ -18,9 +19,9 @@ public class Audiences {
private final ServerProcess serverProcess;
private final SingleAudienceProvider audience;

public Audiences(ServerProcess serverProcess) {
public Audiences(ServerProcess serverProcess, ConnectionManager connectionManager, CommandManager commandManager) {
this.serverProcess = serverProcess;
audience = new SingleAudienceProvider(serverProcess);
audience = new SingleAudienceProvider(serverProcess, connectionManager, commandManager);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.key.Key;
import net.minestom.server.ServerProcess;
import net.minestom.server.command.CommandManager;
import net.minestom.server.command.ConsoleSender;
import net.minestom.server.entity.Player;
import org.jetbrains.annotations.NotNull;
Expand All @@ -22,9 +23,9 @@ class IterableAudienceProvider implements AudienceProvider<Iterable<? extends Au
private final AudienceRegistry registry = new AudienceRegistry(new ConcurrentHashMap<>(), CopyOnWriteArrayList::new);
private final ServerProcess serverProcess;

protected IterableAudienceProvider(ServerProcess serverProcess) {
protected IterableAudienceProvider(ServerProcess serverProcess, CommandManager commandManager) {
this.serverProcess = serverProcess;
this.console = List.of(serverProcess.getCommandManager().getConsoleSender());
this.console = List.of(commandManager.getConsoleSender());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ public ServerProcess getServerProcess() {
* @param packet the packet to broadcast
*/
default void sendGroupedPacket(@NotNull ServerPacket packet) {
PacketUtils.sendGroupedPacket(getServerProcess(), getPlayers(), packet);
PacketUtils.sendGroupedPacket(getServerProcess().getServerSetting(), getPlayers(), packet);
}

@Override
default void sendMessage(@NotNull Identity source, @NotNull Component message, @NotNull MessageType type) {
Messenger.sendMessage(getServerProcess(), this.getPlayers(), message, ChatPosition.fromMessageType(type), source.uuid());
Messenger.sendMessage(getServerProcess().getServerSetting(), this.getPlayers(), message, ChatPosition.fromMessageType(type), source.uuid());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.key.Key;
import net.minestom.server.ServerProcess;
import net.minestom.server.command.CommandManager;
import net.minestom.server.entity.Player;
import net.minestom.server.network.ConnectionManager;
import org.jetbrains.annotations.NotNull;

import java.util.function.Predicate;
Expand All @@ -20,11 +22,11 @@ class SingleAudienceProvider implements AudienceProvider<Audience> {
@NotNull
private final ServerProcess serverProcess;

protected SingleAudienceProvider(ServerProcess serverProcess) {
protected SingleAudienceProvider(ServerProcess serverProcess, ConnectionManager connectionManager, CommandManager commandManager) {
this.serverProcess = serverProcess;
this.collection = new IterableAudienceProvider(serverProcess);
this.players = PacketGroupingAudience.of(serverProcess, serverProcess.getConnectionManager().getOnlinePlayers());
this.server = Audience.audience(this.players, serverProcess.getCommandManager().getConsoleSender());
this.collection = new IterableAudienceProvider(serverProcess, commandManager);
this.players = PacketGroupingAudience.of(serverProcess, connectionManager.getOnlinePlayers());
this.server = Audience.audience(this.players, commandManager.getConsoleSender());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,28 @@ class BossBarListener implements BossBar.Listener {

@Override
public void bossBarNameChanged(@NotNull BossBar bar, @NotNull Component oldName, @NotNull Component newName) {
this.doIfRegistered(bar, holder -> PacketUtils.sendGroupedPacket(serverProcess, holder.players, holder.createTitleUpdate(newName)));
this.doIfRegistered(bar, holder -> PacketUtils.sendGroupedPacket(serverProcess.getServerSetting(), holder.players, holder.createTitleUpdate(newName)));
}

@Override
public void bossBarProgressChanged(@NotNull BossBar bar, float oldProgress, float newProgress) {
this.doIfRegistered(bar, holder -> PacketUtils.sendGroupedPacket(serverProcess, holder.players, holder.createPercentUpdate(newProgress)));
this.doIfRegistered(bar, holder -> PacketUtils.sendGroupedPacket(serverProcess.getServerSetting(), holder.players, holder.createPercentUpdate(newProgress)));

}

@Override
public void bossBarColorChanged(@NotNull BossBar bar, @NotNull BossBar.Color oldColor, @NotNull BossBar.Color newColor) {
this.doIfRegistered(bar, holder -> PacketUtils.sendGroupedPacket(serverProcess, holder.players, holder.createColorUpdate(newColor)));
this.doIfRegistered(bar, holder -> PacketUtils.sendGroupedPacket(serverProcess.getServerSetting(), holder.players, holder.createColorUpdate(newColor)));
}

@Override
public void bossBarOverlayChanged(@NotNull BossBar bar, BossBar.@NotNull Overlay oldOverlay, BossBar.@NotNull Overlay newOverlay) {
this.doIfRegistered(bar, holder -> PacketUtils.sendGroupedPacket(serverProcess, holder.players, holder.createOverlayUpdate(newOverlay)));
this.doIfRegistered(bar, holder -> PacketUtils.sendGroupedPacket(serverProcess.getServerSetting(), holder.players, holder.createOverlayUpdate(newOverlay)));
}

@Override
public void bossBarFlagsChanged(@NotNull BossBar bar, @NotNull Set<BossBar.Flag> flagsAdded, @NotNull Set<BossBar.Flag> flagsRemoved) {
this.doIfRegistered(bar, holder -> PacketUtils.sendGroupedPacket(serverProcess, holder.players, holder.createFlagsUpdate()));
this.doIfRegistered(bar, holder -> PacketUtils.sendGroupedPacket(serverProcess.getServerSetting(), holder.players, holder.createFlagsUpdate()));
}

private void doIfRegistered(@NotNull BossBar bar, @NotNull Consumer<BossBarHolder> consumer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void addBossBar(@NotNull Collection<Player> players, @NotNull BossBar bar
BossBarHolder holder = this.getOrCreateHandler(bar);
Collection<Player> addedPlayers = players.stream().filter(holder::addViewer).toList();
if (!addedPlayers.isEmpty()) {
PacketUtils.sendGroupedPacket(serverProcess, addedPlayers, holder.createAddPacket());
PacketUtils.sendGroupedPacket(serverProcess.getServerSetting(), addedPlayers, holder.createAddPacket());
}
}

Expand All @@ -91,7 +91,7 @@ public void removeBossBar(@NotNull Collection<Player> players, @NotNull BossBar
if (holder != null) {
Collection<Player> removedPlayers = players.stream().filter(holder::removeViewer).toList();
if (!removedPlayers.isEmpty()) {
PacketUtils.sendGroupedPacket(serverProcess, removedPlayers, holder.createRemovePacket());
PacketUtils.sendGroupedPacket(serverProcess.getServerSetting(), removedPlayers, holder.createRemovePacket());
}
}
}
Expand All @@ -104,7 +104,7 @@ public void removeBossBar(@NotNull Collection<Player> players, @NotNull BossBar
public void destroyBossBar(@NotNull BossBar bossBar) {
BossBarHolder holder = this.bars.remove(bossBar);
if (holder != null) {
PacketUtils.sendGroupedPacket(serverProcess, holder.players, holder.createRemovePacket());
PacketUtils.sendGroupedPacket(serverProcess.getServerSetting(), holder.players, holder.createRemovePacket());
for (Player player : holder.players) {
this.removePlayer(player, holder);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/minestom/server/command/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,15 @@ class Reflection {
try {
callable.call();
} catch (Exception e) {
serverProcess.getExceptionManager().handleException(e);
serverProcess.getExceptionHandler().handleException(e);
}
});
return CommandResult.of(CommandResult.Type.UNKNOWN, rawCommand);
} else {
return callable.call();
}
} catch (Exception e) {
serverProcess.getExceptionManager().handleException(e);
serverProcess.getExceptionHandler().handleException(e);
return CommandResult.of(CommandResult.Type.UNKNOWN, rawCommand);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Duration parse(@NotNull CommandSender sender, @NotNull String input) thro

TemporalUnit timeUnit;
if (Character.isDigit(lastChar))
timeUnit = TimeUnit.getServerTick(sender.getServerProcess().getMinecraftServer());
timeUnit = TimeUnit.getServerTick(sender.getServerProcess().getServerSetting());
else if (SUFFIXES.contains(lastChar)) {
input = input.substring(0, input.length() - 1);

Expand All @@ -52,7 +52,7 @@ else if (SUFFIXES.contains(lastChar)) {
} else if (lastChar == 's') {
timeUnit = TimeUnit.SECOND;
} else if (lastChar == 't') {
timeUnit = TimeUnit.getServerTick(sender.getServerProcess().getMinecraftServer());
timeUnit = TimeUnit.getServerTick(sender.getServerProcess().getServerSetting());
} else {
throw new ArgumentSyntaxException("Time needs to have the unit d, s, t, or none", input, NO_NUMBER);
}
Expand Down
Loading

0 comments on commit 5ad4b14

Please sign in to comment.