Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server crashes when using item.DisplayName() #820

Open
lightyisreal opened this issue Oct 19, 2023 · 3 comments
Open

Server crashes when using item.DisplayName() #820

lightyisreal opened this issue Oct 19, 2023 · 3 comments

Comments

@lightyisreal
Copy link
Contributor

My give command shows up the item's display name based on the language the player is using. Right when I output the success of the command, the server crashes.

func (t Give) Run(source cmd.Source, output *cmd.Output) {
	targets := t.Player
	itemName := t.ItemName

	data, dataUsed := t.Data.Load()
	if !dataUsed {
		data = 0
	}

	name := string(itemName)
	if !strings.Contains(name, ":") {
		name = "minecraft:" + name
	}

	itemType, isItem := world.ItemByName(name, data)

	if !isItem || name == "air" {
		output.Errorf("Unknown item identifier provided %s", name)
		return
	}

	amount16, amountUsed := t.Amount.Load()
	amount := 0
	if !amountUsed {
		amount = 1
	} else {
		amount = int(math.Max(1, float64(amount16)))
	}

	langTag := language.English
	if p, ok := source.(*player.Player); ok {
		langTag = p.Locale()
	}

	var players = make([]*player.Player, 0)
	for _, target := range targets {
		plr, ok := target.(*player.Player)
		if !ok || plr == nil {
			continue
		}
		players = append(players, plr)
	}

	for _, p := range players {
		if p == nil {
			continue
		}
		given := giveItem(p, itemType, data, amount)
		output.Printf("Gave %s x%d to %s", item.DisplayName(itemType, langTag), given, p.Name())
	}
}
panic: should never happen [recovered]
        panic: should never happen

goroutine 33 [running]:
github.com/df-mc/dragonfly/server/session.(*Session).handlePackets.func1()
        C:/Users/Anthony/go/pkg/mod/github.com/df-mc/[email protected]/server/session/session.go:303 +0x69
panic({0x94eb00?, 0xe32860?})
        C:/Program Files/Go/src/runtime/panic.go:914 +0x21f
github.com/df-mc/dragonfly/server/item.DisplayName({0xe36c60, 0xc000d3f8d1}, {0xf8d1?, 0xd3?, {0x0?, 0x0?}})
        C:/Users/Anthony/go/pkg/mod/github.com/df-mc/[email protected]/server/item/item.go:220 +0xa6
github.com/imlighty/hardcore/server/cmd.Give.Run({{0xc000c1a0c0, 0x1, 0x1}, {0xc00037e7e0, 0xd}, {0x0, 0x0}, {0x0, 0x0}}, {0xe3e450, ...}, ...)
        D:/Projects/Hardcore/server/cmd/give.go:120 +0x5c9
github.com/df-mc/dragonfly/server/cmd.Command.executeRunnable({{0xc0010c85d0, 0x1, 0x1}, {0xa512d5, 0x4}, {0xa624b7, 0x19}, {0xc0017d8140, 0x3d}, {0x1652800, ...}}, ...)
        C:/Users/Anthony/go/pkg/mod/github.com/df-mc/[email protected]/server/cmd/command.go:269 +0x88d
github.com/df-mc/dragonfly/server/cmd.Command.Execute({{0xc0010c85d0, 0x1, 0x1}, {0xa512d5, 0x4}, {0xa624b7, 0x19}, {0xc0017d8140, 0x3d}, {0x1652800, ...}}, ...)
        C:/Users/Anthony/go/pkg/mod/github.com/df-mc/[email protected]/server/cmd/command.go:138 +0x298
github.com/df-mc/dragonfly/server/player.(*Player).ExecuteCommand(0xc000ada000, {0xc00020a120, 0x1e})
        C:/Users/Anthony/go/pkg/mod/github.com/df-mc/[email protected]/server/player/player.go:387 +0x367
github.com/df-mc/dragonfly/server/session.(*CommandRequestHandler).Handle(0x972a80?, {0xe3bab8?, 0xc00394a140?}, 0xc0005fe000?)
        C:/Users/Anthony/go/pkg/mod/github.com/df-mc/[email protected]/server/session/handler_command_request.go:22 +0xa2
github.com/df-mc/dragonfly/server/session.(*Session).handlePacket(0xc0005fe000, {0xe3bab8, 0xc00394a140})
        C:/Users/Anthony/go/pkg/mod/github.com/df-mc/[email protected]/server/session/session.go:432 +0x8d
github.com/df-mc/dragonfly/server/session.(*Session).handlePackets(0xc0005fe000)
        C:/Users/Anthony/go/pkg/mod/github.com/df-mc/[email protected]/server/session/session.go:312 +0xdc
created by github.com/df-mc/dragonfly/server/session.(*Session).Start in goroutine 1
        C:/Users/Anthony/go/pkg/mod/github.com/df-mc/[email protected]/server/session/session.go:217 +0xa5

Process finished with the exit code 2
@lightyisreal
Copy link
Contributor Author

It happens specifically when giving myself blue_concrete

@Flonja
Copy link
Contributor

Flonja commented Apr 28, 2024

this also happens with a block.Log

@RestartFU
Copy link
Contributor

turns out this only seems to work properly with british english, so use that instead for the time being

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

No branches or pull requests

3 participants