Skip to content

Commit

Permalink
feat: add MinecraftCommands class
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Mar 3, 2024
1 parent ce0dca4 commit c80b460
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 12 deletions.
17 changes: 17 additions & 0 deletions include/bedrock/command/command_output_sender.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

class CommandOutputSender {};
38 changes: 38 additions & 0 deletions include/bedrock/command/minecraft_commands.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include "bedrock/command/command_output_sender.h"
#include "bedrock/command/command_registry.h"

class MinecraftCommands {
public:
virtual ~MinecraftCommands() = default;

[[nodiscard]] CommandOutputSender &getOutputSender() const
{
return *output_sender_;
}

[[nodiscard]] CommandRegistry &getRegistry() const
{
return *registry_;
}

private:
std::unique_ptr<CommandOutputSender> output_sender_;
std::unique_ptr<CommandRegistry> registry_;
};
static_assert(sizeof(MinecraftCommands) == 24);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, The Endstone Project. (https://endstone.dev) All Rights Reserved.
// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -14,17 +14,9 @@

#pragma once

#include <memory>
#include "bedrock/command/minecraft_commands.h"

#include "bedrock/bedrock.h"
#include "bedrock/core.h"

class DedicatedServer {
class Minecraft {
public:
enum class StartResult;

BEDROCK_API DedicatedServer::StartResult runDedicatedServerLoop(
Core::FilePathManager &file_path_manager, class PropertiesSettings &properties_settings,
class LevelSettings &level_settings, class AllowListFile &allow_list_file,
class std::unique_ptr<class PermissionsFile> &permissions_file);
MinecraftCommands &getCommands();
};
24 changes: 24 additions & 0 deletions src/endstone_runtime/bedrock/minecraft.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "bedrock/minecraft.h"

MinecraftCommands &Minecraft::getCommands()
{
#ifdef __linux__
return *reinterpret_cast<MinecraftCommands *>(reinterpret_cast<size_t *>(this) + 22);
#elif _WIN32
return *reinterpret_cast<MinecraftCommands *>(reinterpret_cast<size_t *>(this) + 23);
#endif
}

0 comments on commit c80b460

Please sign in to comment.