diff --git a/README.md b/README.md index c21b0ca..089dcf7 100644 --- a/README.md +++ b/README.md @@ -262,8 +262,9 @@ to generate our protobuf types, you will need to install [buf](https://buf.build # Install buf # Follow instructions at https://buf.build/docs/cli/installation/ -# Install protoc-gen-go +# Install protoc-gen-go and protoc-gen-go-grpc go install google.golang.org/protobuf/cmd/protoc-gen-go@latest +go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest ``` Then run: diff --git a/plugin/adapters/plugin/actions.go b/plugin/adapters/plugin/actions.go index 30efe8f..7f090e7 100644 --- a/plugin/adapters/plugin/actions.go +++ b/plugin/adapters/plugin/actions.go @@ -14,7 +14,7 @@ import ( "github.com/df-mc/dragonfly/server/world/sound" "github.com/go-gl/mathgl/mgl64" "github.com/google/uuid" - pb "github.com/secmc/plugin/proto/generated" + pb "github.com/secmc/plugin/proto/generated/go" ) func (m *Manager) applyActions(p *pluginProcess, batch *pb.ActionBatch) { diff --git a/plugin/adapters/plugin/commands.go b/plugin/adapters/plugin/commands.go index 08db39c..a94accc 100644 --- a/plugin/adapters/plugin/commands.go +++ b/plugin/adapters/plugin/commands.go @@ -6,7 +6,7 @@ import ( "github.com/df-mc/dragonfly/server/cmd" "github.com/df-mc/dragonfly/server/player" "github.com/df-mc/dragonfly/server/world" - pb "github.com/secmc/plugin/proto/generated" + pb "github.com/secmc/plugin/proto/generated/go" ) func (m *Manager) registerCommands(p *pluginProcess, specs []*pb.CommandSpec) { diff --git a/plugin/adapters/plugin/custom_items.go b/plugin/adapters/plugin/custom_items.go index 02f80cd..daea3e8 100644 --- a/plugin/adapters/plugin/custom_items.go +++ b/plugin/adapters/plugin/custom_items.go @@ -8,7 +8,7 @@ import ( "github.com/df-mc/dragonfly/server/item/category" "github.com/df-mc/dragonfly/server/world" - pb "github.com/secmc/plugin/proto/generated" + pb "github.com/secmc/plugin/proto/generated/go" ) // customItem implements world.CustomItem diff --git a/plugin/adapters/plugin/event_helpers.go b/plugin/adapters/plugin/event_helpers.go index 2022920..a6ee4e6 100644 --- a/plugin/adapters/plugin/event_helpers.go +++ b/plugin/adapters/plugin/event_helpers.go @@ -12,7 +12,7 @@ import ( "github.com/df-mc/dragonfly/server/session" "github.com/df-mc/dragonfly/server/world" "github.com/go-gl/mathgl/mgl64" - pb "github.com/secmc/plugin/proto/generated" + pb "github.com/secmc/plugin/proto/generated/go" ) type cancelContext interface { @@ -272,4 +272,3 @@ func worldFromContext(ctx *world.Context) *world.World { } return tx.World() } - diff --git a/plugin/adapters/plugin/manager.go b/plugin/adapters/plugin/manager.go index 4c9aa9f..c4317d5 100644 --- a/plugin/adapters/plugin/manager.go +++ b/plugin/adapters/plugin/manager.go @@ -22,7 +22,7 @@ import ( "github.com/secmc/plugin/plugin/adapters/grpc" "github.com/secmc/plugin/plugin/config" "github.com/secmc/plugin/plugin/ports" - pb "github.com/secmc/plugin/proto/generated" + pb "github.com/secmc/plugin/proto/generated/go" ) type Manager struct { diff --git a/plugin/adapters/plugin/player_events.go b/plugin/adapters/plugin/player_events.go index 42139ce..fd68855 100644 --- a/plugin/adapters/plugin/player_events.go +++ b/plugin/adapters/plugin/player_events.go @@ -12,7 +12,7 @@ import ( "github.com/df-mc/dragonfly/server/session" "github.com/df-mc/dragonfly/server/world" "github.com/go-gl/mathgl/mgl64" - pb "github.com/secmc/plugin/proto/generated" + pb "github.com/secmc/plugin/proto/generated/go" ) func (m *Manager) EmitPlayerJoin(p *player.Player) { diff --git a/plugin/adapters/plugin/process.go b/plugin/adapters/plugin/process.go index e1423f7..5611c98 100644 --- a/plugin/adapters/plugin/process.go +++ b/plugin/adapters/plugin/process.go @@ -18,7 +18,7 @@ import ( "github.com/secmc/plugin/plugin/adapters/grpc" "github.com/secmc/plugin/plugin/config" - pb "github.com/secmc/plugin/proto/generated" + pb "github.com/secmc/plugin/proto/generated/go" ) const ( diff --git a/plugin/adapters/plugin/world_events.go b/plugin/adapters/plugin/world_events.go index 111fb47..34efae0 100644 --- a/plugin/adapters/plugin/world_events.go +++ b/plugin/adapters/plugin/world_events.go @@ -7,7 +7,7 @@ import ( "github.com/df-mc/dragonfly/server/block/cube" "github.com/df-mc/dragonfly/server/world" "github.com/go-gl/mathgl/mgl64" - pb "github.com/secmc/plugin/proto/generated" + pb "github.com/secmc/plugin/proto/generated/go" ) func (m *Manager) EmitWorldLiquidFlow(ctx *world.Context, from, into cube.Pos, liquid world.Liquid, replaced world.Block) { diff --git a/plugin/ports/ports.go b/plugin/ports/ports.go index 38c1a3e..750171f 100644 --- a/plugin/ports/ports.go +++ b/plugin/ports/ports.go @@ -12,7 +12,7 @@ import ( "github.com/df-mc/dragonfly/server/session" "github.com/df-mc/dragonfly/server/world" "github.com/go-gl/mathgl/mgl64" - pb "github.com/secmc/plugin/proto/generated" + pb "github.com/secmc/plugin/proto/generated/go" ) type PluginManager interface { diff --git a/proto/buf.gen.yaml b/proto/buf.gen.yaml index 50c4ad5..760a09d 100644 --- a/proto/buf.gen.yaml +++ b/proto/buf.gen.yaml @@ -5,8 +5,13 @@ managed: - file_option: go_package_prefix value: github.com/secmc/plugin/proto/generated plugins: + # Go - local: protoc-gen-go - out: generated + out: generated/go + opt: + - paths=source_relative + - remote: buf.build/grpc/go + out: generated/go opt: - paths=source_relative # C++ diff --git a/proto/generated/actions.pb.go b/proto/generated/go/actions.pb.go similarity index 100% rename from proto/generated/actions.pb.go rename to proto/generated/go/actions.pb.go diff --git a/proto/generated/command.pb.go b/proto/generated/go/command.pb.go similarity index 100% rename from proto/generated/command.pb.go rename to proto/generated/go/command.pb.go diff --git a/proto/generated/common.pb.go b/proto/generated/go/common.pb.go similarity index 100% rename from proto/generated/common.pb.go rename to proto/generated/go/common.pb.go diff --git a/proto/generated/mutations.pb.go b/proto/generated/go/mutations.pb.go similarity index 100% rename from proto/generated/mutations.pb.go rename to proto/generated/go/mutations.pb.go diff --git a/proto/generated/player_events.pb.go b/proto/generated/go/player_events.pb.go similarity index 100% rename from proto/generated/player_events.pb.go rename to proto/generated/go/player_events.pb.go diff --git a/proto/generated/plugin.pb.go b/proto/generated/go/plugin.pb.go similarity index 100% rename from proto/generated/plugin.pb.go rename to proto/generated/go/plugin.pb.go diff --git a/proto/generated/go/plugin_grpc.pb.go b/proto/generated/go/plugin_grpc.pb.go new file mode 100644 index 0000000..ab6f4c6 --- /dev/null +++ b/proto/generated/go/plugin_grpc.pb.go @@ -0,0 +1,115 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.5.1 +// - protoc (unknown) +// source: plugin.proto + +package generated + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 + +const ( + Plugin_EventStream_FullMethodName = "/df.plugin.Plugin/EventStream" +) + +// PluginClient is the client API for Plugin service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type PluginClient interface { + EventStream(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[PluginToHost, HostToPlugin], error) +} + +type pluginClient struct { + cc grpc.ClientConnInterface +} + +func NewPluginClient(cc grpc.ClientConnInterface) PluginClient { + return &pluginClient{cc} +} + +func (c *pluginClient) EventStream(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[PluginToHost, HostToPlugin], error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + stream, err := c.cc.NewStream(ctx, &Plugin_ServiceDesc.Streams[0], Plugin_EventStream_FullMethodName, cOpts...) + if err != nil { + return nil, err + } + x := &grpc.GenericClientStream[PluginToHost, HostToPlugin]{ClientStream: stream} + return x, nil +} + +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type Plugin_EventStreamClient = grpc.BidiStreamingClient[PluginToHost, HostToPlugin] + +// PluginServer is the server API for Plugin service. +// All implementations must embed UnimplementedPluginServer +// for forward compatibility. +type PluginServer interface { + EventStream(grpc.BidiStreamingServer[PluginToHost, HostToPlugin]) error + mustEmbedUnimplementedPluginServer() +} + +// UnimplementedPluginServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedPluginServer struct{} + +func (UnimplementedPluginServer) EventStream(grpc.BidiStreamingServer[PluginToHost, HostToPlugin]) error { + return status.Errorf(codes.Unimplemented, "method EventStream not implemented") +} +func (UnimplementedPluginServer) mustEmbedUnimplementedPluginServer() {} +func (UnimplementedPluginServer) testEmbeddedByValue() {} + +// UnsafePluginServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to PluginServer will +// result in compilation errors. +type UnsafePluginServer interface { + mustEmbedUnimplementedPluginServer() +} + +func RegisterPluginServer(s grpc.ServiceRegistrar, srv PluginServer) { + // If the following call pancis, it indicates UnimplementedPluginServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } + s.RegisterService(&Plugin_ServiceDesc, srv) +} + +func _Plugin_EventStream_Handler(srv interface{}, stream grpc.ServerStream) error { + return srv.(PluginServer).EventStream(&grpc.GenericServerStream[PluginToHost, HostToPlugin]{ServerStream: stream}) +} + +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type Plugin_EventStreamServer = grpc.BidiStreamingServer[PluginToHost, HostToPlugin] + +// Plugin_ServiceDesc is the grpc.ServiceDesc for Plugin service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Plugin_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "df.plugin.Plugin", + HandlerType: (*PluginServer)(nil), + Methods: []grpc.MethodDesc{}, + Streams: []grpc.StreamDesc{ + { + StreamName: "EventStream", + Handler: _Plugin_EventStream_Handler, + ServerStreams: true, + ClientStreams: true, + }, + }, + Metadata: "plugin.proto", +} diff --git a/proto/generated/world_events.pb.go b/proto/generated/go/world_events.pb.go similarity index 100% rename from proto/generated/world_events.pb.go rename to proto/generated/go/world_events.pb.go diff --git a/scripts/post_generation.sh b/scripts/post_generation.sh index d6f26ce..2b146d4 100755 --- a/scripts/post_generation.sh +++ b/scripts/post_generation.sh @@ -4,5 +4,5 @@ cd ts npm install npm run build -cd .. +cd ../go go mod tidy