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

Non-static API #125

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

Non-static API #125

wants to merge 17 commits into from

Conversation

MelonHell
Copy link

I think this is a serious problem for Minestom and it needs to be addressed.

  1. You cannot run two Minestom servers in one application.
  2. It is impossible to replace components such as ConnectionManager with custom implementations.

When this is completed, it will definitely break backwards compatibility, but the sooner it is fixed, the less painful it will be

will resolves #70 and #119

@mworzala
Copy link

I'm probably down to merge this, but I will have to see of course

@DasBabyPixel
Copy link

Backwards compatibility could be kept if the static methods redirect to the first instance created. Kind of ugly, but that way there could be a deprecation phase to adapt. Not saying that this should be done, just pointing out options.

@mworzala
Copy link

I think it should probably just be done with another update like 1.20.5 or 1.21 which already may have breaking changes

@MelonHell
Copy link
Author

Now it's running! I look forward to reviews, criticism and suggestions for improvement 🙂

@MelonHell MelonHell marked this pull request as ready for review January 29, 2024 16:27
@mworzala
Copy link

Small PR.... (I will start going through it soon)

@mworzala mworzala linked an issue Jan 29, 2024 that may be closed by this pull request
@wordandahalf
Copy link

I'm skeptical of the need for MinecraftServerObject. It seems like an unneeded level of abstraction. In any case, I do think having a Server interface which MinecraftServer implements could provide flexibility useful to user.

@MelonHell
Copy link
Author

MelonHell commented Jan 30, 2024

In any case, I do think having a Server interface which MinecraftServer implements could provide flexibility useful to user.

I agree, I need to make an interface, otherwise this PR is useless :)

@MelonHell
Copy link
Author

I thought it would be much simpler, but there is still a huge amount of work since many mistakes were made when designing Minestom

@MelonHell
Copy link
Author

I think you can create a separate repository for this and call it minestom-ee 😄

@mworzala
Copy link

I just barely started reviewing, but in no world is Lombok being added to Minestom.

Copy link

@mworzala mworzala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only got a small way through, will continue later.

demo/src/main/java/net/minestom/demo/Main.java Outdated Show resolved Hide resolved
demo/src/main/java/net/minestom/demo/PlayerInit.java Outdated Show resolved Hide resolved
@@ -187,24 +71,145 @@ public class PlayerInit {
// System.out.println("load end");
// });

inventory = new Inventory(InventoryType.CHEST_1_ROW, Component.text("Test inventory"));
inventory = new Inventory(serverFacade.getGlobalEventHandler(), serverFacade.getServerSettings(), InventoryType.CHEST_1_ROW, Component.text("Test inventory"));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inventory should probably get the server references it needs from the player it is opened for

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

help needed

ItemStack droppedItem = event.getItemStack();

Pos playerPos = player.getPosition();
ItemEntity itemEntity = new ItemEntity(serverFacade, droppedItem);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of odd cases created now because you could try to spawn an entity in a level of server A while passing server B into the constructor. These probably need to be handled somewhere and I'm not sure they are (im still on like file 2 of review)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, two different servers can have common components, for example a common ExceptionHandler

}).repeat(10, TimeUnit.SERVER_TICK); //.schedule();
final Component footer = BenchmarkManager.getCpuMonitoringMessage(benchmarkManager);
serverFacade.getAudienceManager().players().sendPlayerListHeaderAndFooter(header, footer);
}).repeat(10, TimeUnit.getServerTick(serverFacade.getServerSettings())); //.schedule();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO another method should be added to take a SERVER_TICKS constant which the scheduler can then get from the server rather than it being a TimeUnit and requiring a reference to the server here.

Copy link
Author

@MelonHell MelonHell Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SERVER_TICKS is no longer a constant, as it is a parameter that may differ between server instances

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I mean there should be a constant to represent server ticks and converted when encountered

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

help needed

src/main/java/net/minestom/server/ServerFacadeImpl.java Outdated Show resolved Hide resolved
this.audienceManager = new AudienceManagerImpl(commandManager, this, this);
this.ticker = new TickerImpl(this);
this.serverStarter = new ServerStarter(this);
this.mojangAuth = new MojangAuth(this, this);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be present unless used, perhaps it would be better to have some generic AuthProvider which this, velocity, bungee implement to prevent the confusion of enabling multiple at once.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree but I need help with this

src/main/java/net/minestom/server/ServerSettings.java Outdated Show resolved Hide resolved
src/main/java/net/minestom/server/ServerStarter.java Outdated Show resolved Hide resolved
import java.util.concurrent.atomic.AtomicBoolean;

@RequiredArgsConstructor
public class ServerStarter {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little unclear on the need for this class

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is needed to start the server (now renamed to ServerProcess). Since MinecraftServer is optional for running Minestom, there should be no logic in it, so the launch logic is in a separate class

build.gradle.kts Outdated
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests will be fixed and enabled after other changes are approved

"The server from the Instance should be passed into the chunk supplier, this should remain a method reference."
@@ -58,40 +58,42 @@ default boolean isViewer(@NotNull Player player) {
*
* @param packet the packet to send to all viewers
*/
default void sendPacketToViewers(@NotNull SendablePacket packet) {
default void sendPacketToViewers(ServerSettingsProvider serverSettingsProvider, @NotNull SendablePacket packet) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that ServerSettings is required here, but I don't know how to fix it

@MelonHell
Copy link
Author

I need help with:

Who is interested in this pull request please help me 🥺

@Rollczi
Copy link

Rollczi commented Feb 10, 2024

  • Make Inventory undepended from GlobalEventHandler and ServerSettings

@MelonHell Hi, I think you can move some dependencies:
from
image

we can do this by using interfaces to dependency inversion:
Player can implement EventReceiver (I don't know how to name it exactly), also we can add a interface for PlayerInventory.
image

Generally, this is a solution to this problem, but I also have a proposal to create a class "InventoryFactory"/"InventoryManager", which will create new inventory. This may help create new inventories that will need additional dependencies.
image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add more Object-oriented programming API. Add non static net.minestom.server.MinecraftServer
5 participants