Exemplo n.º 1
0
func cmdTp(player gamerules.IPlayerClient, message string, cmdHandler gamerules.IGame) {
	args := strings.Split(message, " ")
	if len(args) < 3 {
		player.EchoMessage(tpUsage)
		return
	}

	teleportee := cmdHandler.PlayerByName(args[1])
	destination := cmdHandler.PlayerByName(args[2])
	if teleportee == nil {
		msg := fmt.Sprintf("'%s' is not logged in", args[1])
		player.EchoMessage(msg)
		return
	}
	if destination == nil {
		msg := fmt.Sprintf("'%s' is not logged in", args[2])
		player.EchoMessage(msg)
		return
	}

	pos, look := destination.PositionLook()

	// TODO: Remove this hack or figure out what needs to happen instead
	pos.Y += 1.63

	teleportee.EchoMessage(fmt.Sprintf("Hold still! You are being teleported to %s", args[2]))
	msg := fmt.Sprintf("Teleporting %s to %s at (%.2f, %.2f, %.2f)", args[1], args[2], pos.X, pos.Y, pos.Z)
	log.Printf("Message: %s", msg)
	player.EchoMessage(msg)

	teleportee.SetPositionLook(pos, look)
}
Exemplo n.º 2
0
func cmdSay(player gamerules.IPlayerClient, message string, cmdHandler gamerules.IGame) {
	args := strings.Split(message, " ")
	if len(args) < 2 {
		player.EchoMessage(sayUsage)
		return
	}
	msg := strings.Join(args[1:], " ")
	cmdHandler.BroadcastMessage("§d" + msg)
}
Exemplo n.º 3
0
func cmdGive(player gamerules.IPlayerClient, message string, cmdHandler gamerules.IGame) {
	args := strings.Split(message, " ")
	if len(args) < 3 || len(args) > 5 {
		player.EchoMessage(giveUsage)
		return
	}
	args = args[1:]

	// Check to make sure this is a valid player name (at the moment command
	// is being run, the player may log off before command completes).
	target := cmdHandler.PlayerByName(args[0])

	if target == nil {
		msg := fmt.Sprintf("'%s' is not logged in", args[0])
		player.EchoMessage(msg)
		return
	}

	itemNum, err := strconv.Atoi(args[1])
	itemType, ok := cmdHandler.ItemTypeById(itemNum)
	if err != nil || !ok {
		msg := fmt.Sprintf("'%s' is not a valid item id", args[1])
		player.EchoMessage(msg)
		return
	}

	quantity := 1
	if len(args) >= 3 {
		quantity, err = strconv.Atoi(args[2])
		if err != nil {
			player.EchoMessage(giveUsage)
			return
		}

		if quantity > 512 {
			msg := "Cannot give more than 512 items at once"
			player.EchoMessage(msg)
			return
		}
	}

	data := 0
	if len(args) >= 4 {
		data, err = strconv.Atoi(args[2])
		if err != nil {
			player.EchoMessage(giveUsage)
			return
		}
	}

	// Perform the actual give
	msg := fmt.Sprintf("Giving %d of '%s' to %s", quantity, itemType.Name, args[0])
	player.EchoMessage(msg)

	maxStack := int(itemType.MaxStack)

	for quantity > 0 {
		count := quantity
		if count > maxStack {
			count = maxStack
		}

		item := gamerules.Slot{
			ItemTypeId: itemType.Id,
			Count:      ItemCount(count),
			Data:       ItemData(data),
		}
		target.GiveItem(item)
		quantity -= count
	}

	if player != target {
		msg = fmt.Sprintf("%s gave you %d of '%s'", player, quantity, itemType.Name)
		target.EchoMessage(msg)
	}
}