Adding client-side and server-side interactions. Also adds purpur/paper support
This commit is contained in:
@@ -23,6 +23,13 @@ func (testPlugin) Chat(context *Context, event ChatEvent) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (testPlugin) ClientTick(context *Context, event ClientTickEvent) error {
|
||||
if event.Connected {
|
||||
context.DisplayClientMessage(event.PlayerName)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestDispatch(t *testing.T) {
|
||||
pluginMu.Lock()
|
||||
registeredPlugin = testPlugin{}
|
||||
@@ -38,6 +45,40 @@ func TestDispatch(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMetadataDefaultsToServerEnvironment(t *testing.T) {
|
||||
pluginMu.Lock()
|
||||
registeredPlugin = testPlugin{}
|
||||
pluginMu.Unlock()
|
||||
|
||||
var got struct {
|
||||
Data Metadata `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(Dispatch(OperationMetadata, nil), &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.Data.Environment != PluginEnvironmentServer {
|
||||
t.Fatalf("environment = %q, want %q", got.Data.Environment, PluginEnvironmentServer)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispatchClientTick(t *testing.T) {
|
||||
pluginMu.Lock()
|
||||
registeredPlugin = testPlugin{}
|
||||
pluginMu.Unlock()
|
||||
|
||||
input, _ := json.Marshal(ClientTickEvent{Connected: true, PlayerName: "Client player"})
|
||||
var got response
|
||||
if err := json.Unmarshal(Dispatch(OperationClientTick, input), &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.Status != "ok" || len(got.Actions) != 1 {
|
||||
t.Fatalf("unexpected client tick response: %#v", got)
|
||||
}
|
||||
if got.Actions[0].Type != "minecraft:client.chat.display" {
|
||||
t.Fatalf("action type = %q", got.Actions[0].Type)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispatchRecoversPanic(t *testing.T) {
|
||||
pluginMu.Lock()
|
||||
registeredPlugin = testPlugin{}
|
||||
|
||||
Reference in New Issue
Block a user